【JQuery】Differences among bind(), live(), delegare, on() and one()

1.Basic usage and description

1.1.bind( eventType [, eventData ], handler(eventObject) )

http://api.jquery.com/bind/

Description: Attach a handler to an event for the elements.

Unbind function:  unblnd()

 

1.2.live( events, handler(eventObject) ) 

 http://api.jquery.com/live/  Remoed from 1.9 version

 Description: Attach an event handler for all elements which match the current selector, now and in the future

Unbind function:  die()

 

1. 3.delegate( selector, eventType, handler(eventObject) )

 http://api.jquery.com/delegate/

 Description: Attach a handler to one or more events for all elements that match the selector, now or in the future, based on a specific set of root elements.

Unbind function:  undelegate()

 

 1.4.on( events [, selector ] [, data ], handler(eventObject) )

 http://api.jquery.com/on/

 Description: Attach an event handler function for one or more events to the selected elements.

Unbind function:  off()

 

1.5.one( events [, data ], handler(eventObject) )

 http://api.jquery.com/one/

 Description: Attach a handler to an event for the elements. The handler is executed at most once per element.

Unbind function:  off()

 

 2.Diffences 

2.1

bind() only can bind the exist elements. live() and  delegate() can bind the elements create in the feature. They find the elements though bubble method .

2.2

delegate() and on() can bind the father elments to bind the children.

 $( "table" ).delegate( "td", "click", function() {

  $( this ).toggleClass( "chosen" );
});

2.4

on() has the same effect but diffenrent usage, be careful about the arguments

$( "table" ).on( "click", "td", function() {

  $( this ).toggleClass( "chosen" );

});

 2.3.

one() only excute for once.

2.5.

In the newest version, all the other bind function is based on on(). And all unbind function are based on off().

Here are some snippets in jquery 1.10.1 (live() has already moved from 1.9)

  

≡≡≡≡≡≡≡≡≡≡≡≡★ From Laker's blog ★≡≡≡≡≡≡≡≡≡≡≡≡

¤ ╭⌒╮☀Coding and changing~☀ ╭╭ ⌒╮

✪Fighting and insisting~✪

posted @ 2013-10-02 16:10  youngLaker  阅读(203)  评论(0编辑  收藏  举报