16

我的 HTML:

<div id="parent">
    <div id="child">cx</div>
</div>

当我使用 jQuery

$('#parent').mouseout(function(){
    //something here
});

我想知道为什么当我的鼠标进入孩子div时功能会触发。我还在 parent 里面div。我希望该mouseout功能仅在我离开父母时才触发,而div不是在我在任何孩子身上时触发div

http://jsbin.com/esiju/ << 例子

干杯

4

3 回答 3

26

这就是mouseleave活动的目的。

$('#parent').mouseleave(function(){
//something here
});

http://api.jquery.com/mouseleave/

于 2010-04-04T17:48:06.607 回答
1

.mouseleave works perfectly here:

$("#parent").mouseleave(function(){
    //Enter stuff that should happen when mouse leaves 
    //the boundaries of the parent element
    // NOT including the children
});

.mouseout fires on mousing over child elements!

于 2014-02-19T11:24:17.733 回答
0

mouseout 和 mouseover 事件之间似乎存在一些差异。jimyi 为您的问题提供了正确的解决方案,我只是想包含一些额外的链接以确保完整性。

于 2010-04-04T18:02:15.157 回答