参考网址:https://zhidao.baidu.com/question/499093977.html
function c(self){
alert(self.id);
}
<input type='button' id='id1' onclick='c(this)'/> 这里传入this,代表当前input
<input type='button' id='id2' onclick='c(this)'/> 这里传入this,代表当前input
本文通过两个具体的HTML按钮示例,介绍了JavaScript中this关键字的使用方法及其如何指向当前操作的DOM元素。通过简单的代码示例,展示了在按钮点击事件中如何正确地引用this来获取当前元素的ID。
参考网址:https://zhidao.baidu.com/question/499093977.html
function c(self){
alert(self.id);
}
<input type='button' id='id1' onclick='c(this)'/> 这里传入this,代表当前input
<input type='button' id='id2' onclick='c(this)'/> 这里传入this,代表当前input
1617

被折叠的 条评论
为什么被折叠?