jQuery bind()Method

jQuery 事件方法jQuery Event Methods

Examples

Add a click event to <p> elements:

$("p").bind("click",function(){
alert("This paragraph was clicked.");
});

Try it Yourself »

Definition and Usage

The bind() method adds one or more event handlers to selected elements, as well as the function to run when the event occurs.

As of jQuery version 1.7,on()the method is the preferred way to add event handlers to selected elements.


Syntax

$(selector).bind(event,data,function,map)

Parameter Description
event Required. Specifies one or more events to add to the element.

Multiple event values separated by spaces. Must be valid events.
data Optional. Specifies additional data to pass to the function.
function Required. Specifies the function to run when the event occurs.
map Specifies an 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 an event map
How to use an 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 事件方法jQuery Event Methods

Other Extensions