开发者

addEventListener: How to access event

开发者 https://www.devze.com 2023-04-06 16:57 出处:网络
I have two questions for the following example: function doIt(){ this.attribute = someValue; // Works as expected

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 appro开发者_Go百科priate way to do 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

function doIt(event)

What is this? - http://howtonode.org/what-is-this

0

精彩评论

暂无评论...
验证码 换一张
取 消