jQuery bind() method
Example
towards
element, add a click event:
$("p").bind("click",function(){
alert("This paragraph was clicked.");
});
Try it »
Definition and Usage
The bind() method adds one or more event handlers to the selected elements, as well as a function to run when the event occurs.
Since jQuery version 1.7,on() method is the preferred way to add event handlers to selected elements.
Syntax
$(
selector
).bind(
event,data,function,map
)
| Parameters | Description |
|---|---|
| event | Required. Specifies one or more events to add to the element. |
由空格分隔多个事件值。必须是有效的事件。 |
| data | Optional. Specifies additional data passed to the function. | | function | Required. Specifies the function to run when the event occurs. | | map | Specifies the event map ({event:function, event:function, ...}), containing one or more events to add to the element and the function to run when the event occurs. |
More examples
Add multiple events
How to add multiple events to an element.
Using the event map
How to use the event map to add some events/functions to selected elements.
Pass data to the function
How to pass data to a custom-named event handler.
jQuery event methods