在 Javascript/jQuery 中 (e) 是什么意思? [英] In Javascript/jQuery what does (e) mean?
问题描述
我是 JavaScript/jQuery 的新手,我一直在学习如何创建函数.许多函数都出现在括号中的 (e) 中.让我告诉你我的意思:
I am new to JavaScript/jQuery and I've been learning how to make functions. A lot of functions have cropped up with (e) in brackets. Let me show you what I mean:
$(this).click(function(e) {
// does something
});
函数似乎总是不使用 (e) 的值,那为什么它经常出现呢?
It always appears that the function doesn't even use the value of (e), so why is it there so often?
推荐答案
e
是 event
对象的简短 var 引用,该对象将传递给事件处理程序.
e
is the short var reference for event
object which will be passed to event handlers.
事件对象本质上有很多有趣的方法和属性,可以在事件处理程序中使用.
The event object essentially has lot of interesting methods and properties that can be used in the event handlers.
在您发布的示例中,点击处理程序是一个 MouseEvent
In the example you have posted is a click handler which is a MouseEvent
$(<element selector>).click(function(e) {
// does something
alert(e.type); //will return you click
}
DEMO - 鼠标事件 DEMO 使用 e.which
和 e.type
一些有用的参考:
http://api.jquery.com/category/events/
http://www.quirksmode.org/js/events_properties.html
http://www.javascriptkit.com/jsref/event.shtml
http://www.quirksmode.org/dom/events/index.html
http://www.w3.org/TR/DOM-Level-3-Events/#event-types-list
这篇关于在 Javascript/jQuery 中 (e) 是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!