8

我的解绑不起作用。

$("img.hoverable").hover(ChangeImage, ChangeBack);
$("a img.hoverable").unbind('hover');

HTML可能是这样的

<img class="hoverable" src="something.jpg"/>
<a href="#"><img class="hoverable" src="something.jpg"/></a>

当我将鼠标悬停在第二个 HTML 上时,仍会触发 ChangeImage。

我不确定我是否正确使用它,有人可以建议吗?

4

4 回答 4

15

尝试

$("img.hoverable").unbind('mouseenter mouseleave');

.hover() 方法绑定了 mouseenter 和 mouseleave 事件的处理程序。所以为了解除绑定,你必须解除mouseenter和mouseleave的绑定。

于 2010-04-28T07:42:30.470 回答
5

hovermouseenter和的伪事件mouseleave。所以你必须解开这些。
或者,如果没有附加其他处理程序,.unbind()则不带参数调用(删除任何处理程序)。

$("a img.hoverable").unbind();
于 2010-04-28T07:42:20.930 回答
0

试试这个:

$("img.hoverable").hover(ChangeImage, ChangeBack);
$("img.hoverable").unbind('hover');
于 2010-04-28T07:41:11.863 回答
0

.hover 是 mouseenter 和 mouseleave 的包装器。

尝试在这些上调用 unbind。

于 2010-04-28T07:42:33.377 回答