【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/
jquery

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

Unbind function:  unblnd()api

 

1.2.live( events, handler(eventObject) ) 

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

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

Unbind function:  die()code

 

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

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

 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.ip

Unbind function:  undelegate()ci

 

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

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

 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~✪

相關文章
相關標籤/搜索