addEventListener:如何访问事件
对于以下示例,我有两个问题:
function doIt(){
this.attribute = someValue; // Works as expected
alert(event.which); // Doesn't work
}
element.addEventListener("click",doIt,false);
问题 1:为什么 this
绑定到函数,而 event
没有绑定?
问题 2:执行此操作的适当方法是什么?
I have two questions for the following example:
function doIt(){
this.attribute = someValue; // Works as expected
alert(event.which); // Doesn't work
}
element.addEventListener("click",doIt,false);
Question 1: Why is this
bound to the function but event
is not?
Question 2: What would be the appropriate way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
this
是 JavaScript 的内置函数。它总是可以访问的。事件
不是。仅当当前方法支持时才可用。您需要有类似
“这是什么”的内容? - http://howtonode.org/what-is-this
this
is a built-in for JavaScript. It is always accessible.event
is not. It is only available if the current method supports it.You would need to have something like
What is
this
? - http://howtonode.org/what-is-this