首页 > 语言 > JavaScript > 正文

javascript中onclick(this)用法介绍

2024-05-06 14:39:40
字体:
来源:转载
供稿:网友
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
}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选