【问题标题】:Confusion with jQuery mouseout event与 jQuery mouseout 事件混淆
【发布时间】:2011-02-04 05:47:18
【问题描述】:

我的 HTML:

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

当我使用 jQuery 时

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

我想知道为什么当我的鼠标进入孩子div 时,函数会触发。我还在父母div 中。 我希望 mouseout 函数仅在我离开父母 div 时触发,而不是在我在任何孩子 div 时触发。

http://jsbin.com/esiju/

干杯

【问题讨论】:

标签: jquery mouse mouseout


【解决方案1】:

这就是mouseleave 事件的用途。

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

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

【讨论】:

    【解决方案2】:

    .mouseleave 在这里完美运行:

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

    .mouseout 将鼠标悬停在子元素上时触发!

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 2010-09-26
        • 2016-10-03
        • 1970-01-01
        • 2011-01-17
        • 2023-04-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-12-02
        相关资源
        最近更新 更多