3个使用this的典型应用

筅森魡賤 提交于 2019-12-09 10:07:11
写出3个使用this的典型应用
1、在html元素事件属性中使用,如:
<input type=”button” οnclick=”put(this);” value=”点击一下”/>
2、构造函数
function click(name, color) {
  this.name = name;
  this.color = color;
}
3、input点击,获取值
<input type="button" id="put" value="点击一下" />
<script type="text/javascript">
    var btn = document.getElementById("put");
    btn.onclick = function() {
        alert(this.value);    //此处的this是按钮元素
    }
</script>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!