且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

livequery已被弃用

更新时间:2023-12-05 10:36:22

livequery .live()完全不同。

。 live()方法使用事件委派来处理页面上任何地方发生的事件。

The .live() method uses event delegation to handle events that occur anywhere on the page.

livequery 将在DOM发生更改时调用处理程序(通过jQuery方法)

livequery will invoke handlers when DOM changes occur (via jQuery methods).

对于下面的示例,当一个元素 class =some_class被添加到DOM(或者class被添加到元素中),第一个处理程序将运行。删除时,第二个。

For the example below, when an element with class="some_class" is added to the DOM (or the class is added to an element), the first handler will run. When removed, the second.

$('.some_class').livequery( function() {

       // apply a plugin to the element
    $(this).somePlugin();

}, function() {

    // clean up after the element was removed

});

livequery应该对实际的需求很少,但在极少数情况下,您需要响应DOM更改,并且无法控制导致这些更改的jQuery,它可能很有用。

There should be little actual need for livequery, but in that rare case where you need to respond to DOM changes, and have no control over the jQuery that is causing those changes, it can be useful.