javascript中onclick(this)用法介绍

Ivy ·
更新时间:2024-09-20
· 531 次阅读

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
}



this onclick JavaScript

需要 登录 后方可回复, 如果你还没有账号请 注册新账号