javascript中onclick(this)用法介绍

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 
}
posted @ 2018-06-05 17:26  手指乐  阅读(1893)  评论(0编辑  收藏  举报