jquery Plugin--dynamic event binding plugin Jquery.livequery.js

Source: Internet
Author: User

http://blog.csdn.net/zzq58157383/article/details/7721974

The dynamic event binding plug-in livequery can be used to register events or trigger callback functions for corresponding DOM elements. Not only the elements that match the selector are bound to events, but the elements that are later added via JavaScript are bound. When the element no longer matches the selector, Livequery automatically cancels the event registration, so that the developer no longer needs to focus on the source of the HTML element, just focus on how to write its bound events

Selecting a DOM element from the jquery selector will persist the Livequery plug-in in real time throughout the DOM range. This means that regardless of whether an element is previously present or dynamically loaded, events are bound, just like CSS adds a style to an element. At the same time, this plug-in is almost without the use of resources to do these functions

Livequery:http://plugins.jquery.com/project/livequery

How to use:

1. Introduction of Jquery.livequery.js

<script src= "Scripts/jquery-1.6.4.js" type= "Text/javascript" ></script>
<script src= "Scripts/jquery.livequery.js" type= "Text/javascript" ></script>

2. Dynamically binding events via Livequery

$ (document). Ready (function () {
$ (' a '). Livequery (' click ', function () {
Alert (' Livequery caused by click ');
return false;
});
$ ("Body"). Append (' <p><a href= ' # ' > Hyperlink b</a> ');
$ ("Body"). Append (' <p><a href= ' # ' > Hyperlink c</a> ');
});

The Livequery plugin can also trigger a callback function for a matching element, triggering another callback function when the element is no longer matched

$ (' Li '). Livequery (function () {
Binding mouseover and Mouseout events using the hover function
$ (this). Hover (function () {
$ (this). addclass (' hover ');
}, function () {
$ (this). Removeclass (' hover ');
});
}, function () {
Unbind MouseOver and Mouseout events
$ (This)
. Unbind (' mouseover ')
. Unbind (' mouseout ');
});

Use the Livequery plugin to register other plugins

if (jquery.livequery)
JQuery.livequery.resisterPlugin ("Method1", "Method2", "method3");

Different from the new live (type, fn) method in jQuery1.3:

1.live also binds an event handler (using delegation) to the current and future matching elements, and can also bind custom events. But the events currently supported are Click/dblclick, Mousedown/up/move/over/out, keydown/press/up, events not yet supported Blur/focus, Mouseenter/leave, Change, submit
The 2.live method does not support the "no event" style callback function provided by Livequery, and live can only bind event handlers
The 3.live method does not have "setup" and "cleanup" procedures, because all events are delegated rather than directly bound on the 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.