站长资源网络编程
javascript中onclick(this)用法介绍
简介this指触发事件的对象 复制代码 代码如下: 复制代码 代码如下: function test(
this指触发事件的对象
复制代码 代码如下:
<input id="myinput" type="text" value="javascript中onclick中的this" onclick="javascript:test(this);"/>
复制代码 代码如下:
function test(obj){
alert(obj); //[object HTMLInputElement]
alert(obj.id); //myinput
alert(obj.value); //javascript中onclick中的this
}
复制代码 代码如下:
<input id="myinput" type="text" value="javascript中onclick中的this" onclick="javascript:test(this);"/>
复制代码 代码如下:
function test(obj){
alert(obj); //[object HTMLInputElement]
alert(obj.id); //myinput
alert(obj.value); //javascript中onclick中的this
}