javascript 这个函数定义中的“e”是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9705172/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 07:31:54  来源:igfitidea点击:

What does "e" mean in this function definition?

javascriptjqueryhtml

提问by xander27

Can I pass an additional parameter to this function?

我可以向这个函数传递一个额外的参数吗?

$("#foold").click( function(e) {
  // CODE
};

For example, I need to pass some X value to this function. Can I write something like this:

例如,我需要将一些 X 值传递给这个函数。我可以写这样的东西吗:

<a href="javascript:void(X)" id="fooId">Foo</a>

to pass value in this function through eor some other way?

通过e或其他方式传递此函数中的值?

回答by SirDarius

Here, eis an event object, as defined here: http://api.jquery.com/category/events/event-object/

这里e是一个事件对象,定义如下:http: //api.jquery.com/category/events/event-object/

Yes you can pass data to the handler, using this form for the click function:

是的,您可以将数据传递给处理程序,使用此表单作为单击函数:

.click( [eventData], handler(eventObject) )

eventData             A map of data that will be passed to the event handler.
handler(eventObject)  A function to execute each time the event is triggered.

It will be accessible as e.datain the handler.

它可以像e.data在处理程序中一样访问。

回答by Sérgio Michels

In this link you can see how to pass params to the JQuery clickfunction jQuery's .click - pass parameters to user function

在此链接中,您可以看到如何将参数传递给JQuery click函数jQuery 的 .click - 将参数传递给用户函数

Basically

基本上

It allows you to pass a data map to the event object that automatically gets fed back to the event handler function by jQuery as the first parameter.

它允许您将数据映射传递给事件对象,该对象自动通过 jQuery 作为第一个参数反馈给事件处理函数。