The usage and difference analysis of Bind,live,delegate and one method in jquery _jquery

Source: Internet
Author: User

The bind () method is used to attach a handler to an event for each matching element and return the jquery object.

. Bind (eventtype[, Evnetdata], Handler (EventObject))

Where the parameter eventtype is a string that contains one or more JavaScript event types, such as the name of the Click,submit or custom event, separating each type with a space when specifying multiple event types; EventData is the map type. Gives the data to be passed to the event handler, handler specifies the function to execute when the event is triggered, EventObject represents the event object.

The. Bind () method attaches the event handler handler to the EventType event for each element in the matching element collection, and can also pass data to the event handler if necessary.

The live () method attaches an event handler to all elements that match the current selector (including existing or future additions) and returns the JQuery object.

. Live (Eventtype,[eventdata],handler)

Where the parameter eventtype is a string that contains one or more JavaScript event types, such as the name of the Click,keydown or custom event, EventData is an optional parameter, the map type, and the data to pass to the event handler. The parameter is added in jQuery1.4; handler is a function that will be executed when the event is triggered

The. Live () method attaches event handler handler to each matching element (containing the currently existing and future additions) EventType event, and can also pass data to the event handler using the participating EventData if necessary.

. The live () method is basic. A variant of the bind () method, which can attach an event handler to an element ·, when the. bind (), the elements of the jquery object match are appended to the event handler, but the elements added later are not appended to the event handler, so You also need to call the. bind () method again on these elements.

The. One () method attaches an event handler to the specified event of the matching element and returns the JQuery object. The event handlers that are attached can only be executed once.

. One (Eventtype,[eventdata],handler (EventObject))

Where the parameter eventtype is a string that contains one or more JavaScript event types, such as the name of the Click,submit or custom event, separating each type with a space when specifying multiple event types; EventData is the map type. Gives the data to be passed to the event handler, handler specifies the function to execute when the event is triggered, EventObject represents the event object.

The. One () method is similar to. bind (), and the event handler that is bound with. One () is automatically unbound after execution.

The. Delegate () method attaches a handler to one or more events that match all elements of the selector (present or future), based on a specific set of root elements.

. Delegate (Selector,eventtype[,eventdata],handler)

Where the parameter selector is a selector for filtering the element that triggers the event; EventType is a string that specifies one or more JavaScript event types (multiple events are separated by spaces), such as Click,keydown or custom event names EventData is the mapping type that represents the data to be passed to the event handler, and handler represents the function that was executed when the event was triggered.

. Delegate () is similar to. Live () to delegate the binding of each event to the specified DOM element.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.