Home > Web Front-end > JS Tutorial > JQuery live函数_jquery

JQuery live函数_jquery

WBOY
Release: 2016-05-16 18:13:31
Original
1175 people have browsed it

Excerpted from jQuery 1.4.1 Chinese reference:

Event Delegate

The

.live() method works on an element that has not yet been added to the DOM due to the use of event delegation: event handlers bound to ancestor elements can respond to events triggered on descendants. The event handler passed to .live() will not be bound to the element, but will be treated as a special event handler and bound to the root node of the DOM tree. In our example, when a new element is clicked, the following steps occur:

  1. Generate a click event and pass it to
    for processing
  2. Since there is no event handler directly bound to
    , the event bubbles up the DOM tree
  3. Events continue to bubble up to the root node of the DOM tree, and this special event handler is bound to it by default.
  4. Execute the special click event handling function bound by .live().
  5. This event handling function first detects the target of the event object to determine whether it needs to continue. This test is implemented by checking whether $(event.target).closest('.clickme') can find a matching element.
  6. If a matching element is found, the original event handler is called.

Since the test in step 5 above is only done when the event occurs, elements added at any time can respond to this event

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template