Home  >  Article  >  Web Front-end  >  jQuery live(type, fn) delegated event implementation_jquery

jQuery live(type, fn) delegated event implementation_jquery

WBOY
WBOYOriginal
2016-05-16 18:45:021254browse

Currently supports click, dblclick, mousedown, mouseup, mousemove, mouseover, mouseout, keydown, keypress, keyup.
Blur, focus, mouseenter, mouseleave, change, submit are not supported yet
Different from bind(), live() can only bind one event at a time.
This method is very similar to traditional bind. The difference is that using live to bind events will bind events to all current and future elements on the page (using delegation). For example, if you use live to bind click events to all li on the page. Then when a li is added to this page in the future, the click event of this newly added li is still available. There is no need to re-bind events to this newly added element.
.live() is very similar to the popular liveQuery plug-in, but has the following main differences:
* .live currently only supports a subset of all events, refer to the description above for the support list.
* .live does not support the "eventless" style callback function provided by liveQuery. .live can only bind event handling functions.
* .live does not have "setup" and "cleanup" processes. Because all events are delegated rather than directly bound to elements.
To remove an event bound with live, please use the die method
Return value
jQuery
Parameters
type (String): one or more event names separated by spaces
fn (Function): The event handling function to be bound
Example
The p generated by clicking still has the same function.
HTML code:

Click me!


jQuery code:

Copy code The code is as follows:

$("p").live("click", function(){
$(this).after("

Another paragraph!

");
});
Statement:
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