2009-10-13 29 views
42

我試過$.unbind('hover'),這不起作用。

+0

你指定什麼元素從解除綁定事件?例如$(「a」)。unbind(「hover」) – Marius 2009-10-13 05:43:45

+0

是的,它由$(「#id」)。hover(...)和$(「#id」)添加。不管用。 – Mask 2009-10-13 05:47:57

+2

可能的重複[如何在jQuery中解除「懸停」?](http://stackoverflow.com/questions/805133/how-do-i-unbind-hover-in-jquery) – madth3 2013-08-15 16:50:25

回答

74

hover功能它只是兩個處理程序綁定到mouseentermouseleave事件short-hand,你應該拆散他們:

$('#item').unbind('mouseenter mouseleave'); 
+4

您可以結合這些調用: '.unbind('mouseover mouseout');' – nickf 2009-10-13 05:47:01

+0

感謝@nickf,編輯後添加您的建議。 – CMS 2009-10-13 05:49:06

+1

它仍然不起作用 – Mask 2009-10-13 05:49:45

-2

您也可以嘗試:

$('#item').bind('hover', function(){return false})

+6

將額外事件處理程序綁定到對象不會覆蓋以前綁定的處理程序。這可能會奏效,因爲'return false'可能會阻止傳播,但這不是一個好的解決方案。 – nickf 2009-10-13 06:05:38

2

tringger解除綁定點擊一下

$('.item').click(function() { 
$('.item').unbind('mouseenter mouseleave'); 
}); 
11

Api documentation on hover

例:要解除綁定上面的例子中使用:

$("td").off('mouseenter mouseleave'); 
+2

'off'和'unbind'有什麼區別? – Ian 2013-12-16 22:45:58

+4

如[** unbind()**](https://api.jquery.com/unbind/)中所定義: 可以使用.unbind()刪除使用.bind()附加的Event處理程序。 (從jQuery 1.7開始,.on()和.off()方法更適合附加和刪除元素上的事件處理程序。)_ – diynevala 2014-07-30 07:58:41