2009-10-26 43 views

回答

7

是的,它仍然有用。 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的函数来实现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'); 
    }); 
相关问题