开发者

difference between e.preventDefault() and event.preventDefault()?

开发者 https://www.devze.com 2023-03-10 00:07 出处:网络
Is there any difference between these two?Or is just one an abbreviation of the other? e.preventDefault() and 开发者_如何学Pythonevent.preventDefault()

Is there any difference between these two? Or is just one an abbreviation of the other?

e.preventDefault() and 开发者_如何学Pythonevent.preventDefault()


Well, the only difference is the name of event object that is being passed into your listener. If you declare the listener like this:

a.click(function(e) {
});

Obviously the name of event variable is "e" and you should call e.preventDefault. In the second case:

a.click(function(event) {
});

the name of the event object is "event", so you're calling event.preventDefault()


e is just an abbreviation for event, it depends on how the argument is accepted


It's just a matter of variable naming. Some people's convention is naming their event variable e, ev, or event. Whichever best suits you.

0

精彩评论

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

关注公众号