jQuery's .click: Passing Parameters to User Functions
Implementing parameter passing in jQuery's .click event handler can be challenging. Although you can call a function without parameters using .click(add_event), passing parameters requires an alternative approach.
Solution 1:
jQuery version 1.4.3 introduced a new feature that allows you to pass a data map to the event object. This map is made available to the event handler function as its first parameter. To utilize this approach, follow these steps:
// Code Template $("selector").click({param1: "Hello", param2: "World"}, cool_function); // Function Implementation function cool_function(event){ alert(event.data.param1); alert(event.data.param2); }
The above is the detailed content of How to Pass Parameters in jQuery's .click Event Handler?. For more information, please follow other related articles on the PHP Chinese website!