【问题标题】:if you have the latest version of jquery, is livequery still useful?如果您有最新版本的 jquery,livequery 是否仍然有用?
【发布时间】:2010-12-10 04:00:16
【问题描述】:

据我了解,livequery 用于在 DOM 更改后维护您的事件。

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

【问题讨论】:

    标签: jquery livequery


    【解决方案1】:

    是的,它仍然有用。 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】:

      livequery() 提供而 live() 没有提供的一个有用功能是每次匹配新元素(和/或不再匹配元素)时触发自定义函数的能力。

      来自docs

      Live Query 也有能力 触发一个函数(回调) 匹配一个新元素和另一个 函数(回调) 元素不再匹配。这 提供了极致的灵活性和 数不清的用例。例如 以下代码使用基于函数 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'); 
          });
      

      【讨论】:

        猜你喜欢
        • 2019-08-29
        • 2018-02-03
        • 2013-08-21
        • 2018-03-11
        • 2023-03-23
        • 2012-10-29
        • 2023-03-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多