最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What does "e" mean in this function definition? - Stack Overflow

programmeradmin10浏览0评论

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:

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

to pass value in this function through e or some other way?

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:

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

to pass value in this function through e or some other way?

Share Improve this question edited Mar 14, 2012 at 15:49 Justin ᚅᚔᚈᚄᚒᚔ 15.4k8 gold badges55 silver badges64 bronze badges asked Mar 14, 2012 at 15:43 xander27xander27 3,1148 gold badges32 silver badges45 bronze badges 4
  • 3 How to pass params: stackoverflow.com/questions/3273350/… – user800014 Commented Mar 14, 2012 at 15:45
  • No. e in that context is the event object that is populated when the event callback is executed. What are you trying to do? – Austin Brunkhorst Commented Mar 14, 2012 at 15:46
  • @sergio-michels pls write your comment as answer - I'll mark it as best. – xander27 Commented Mar 14, 2012 at 15:48
  • @xander27 ok, posted as answer :) – user800014 Commented Mar 14, 2012 at 16:07
Add a comment  | 

2 Answers 2

Reset to default 11

Here, e is an event object, as defined here: 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.data in the handler.

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

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.

发布评论

评论列表(0)

  1. 暂无评论