Introduction to how to use jQuery event delegate()_jquery
WBOYOriginal
2016-05-16 17:48:341215browse
Delegate Definition and Usage
delegate() method adds one or more event handlers to the specified element (belonging to the child elements of the selected element) and specifies to run when these events occur function.
Event handlers using the delegate() method apply to the current or future elements (such as new elements created by scripts).
Adds one or more event handlers to the specified element (a child element of the selected element) and specifies the function to run when these events occur.
Parameters selector,[type],fnString,String,Function V1.4.2 selector: selector string, used to filter elements that trigger events.
type: One or more events attached to the element. Multiple event values separated by spaces. Must be a valid event.
fn: function that runs when the event occurs
selector,[type],[data],fnString,String,Object,Function V1.4.2 selector: selector string , used to filter the element that triggers the event.
type: One or more events attached to the element. Multiple event values separated by spaces. Must be a valid event.
data: extra data passed to the function
fn: function to run when an event occurs
selector, eventsString, String V1.4.3 selector: selector String for the element on which the filter triggered the event.
events: A data map of strings and functions for one or more event types to execute them.
Example Description: Hide or show the p element when the mouse is clicked:
Description: The delegate method can be used as an alternative to the live() method, allowing each event to be bound to a specific DOM element. The following two pieces of code are equivalent:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn