代码之家  ›  专栏  ›  技术社区  ›  mrblah

如果你有最新版本的jquery,livequery还有用吗?

  •  2
  • mrblah  · 技术社区  · 16 年前

    据我所知,livequery用于在DOM更改后维护事件。

    最新版本的jquery不是已经支持了吗?

    2 回复  |  直到 14 年前
        1
  •  7
  •   Community Mohan Dere    6 年前

    是的,它仍然有用。 live() livequery() 可以绑定到用户浏览器提供的任何事件。

    http://docs.jquery.com/Events/live

    可能的事件值: click, dblclick, mousedown, mouseup, mousemove, mouseover, mouseout, keydown, keypress, keyup

    目前不支持: blur, focus, mouseenter, mouseleave, change, submit

    touchstart, touchend 等等。

        2
  •  2
  •   mtyaka    16 年前

    livequery() 提供同时 live() 不是每次匹配新元素(和/或元素不再匹配)时都能触发自定义函数的能力。

    从 docs :

    元素不再匹配。这 提供终极灵活性和 无数的用例。例如 以下代码使用基于函数的 Live Query实现jQuery

    $('li') 
        .livequery(function(){ 
        // use the helper function hover to bind a mouseover and mouseout event 
            $(this) 
                .hover(function() { 
                    $(this).addClass('hover'); 
                }, function() { 
                    $(this).removeClass('hover'); 
                }); 
        }, function() { 
            // unbind the mouseover and mouseout events 
            $(this) 
                .unbind('mouseover') 
                .unbind('mouseout'); 
        });
    
    推荐文章