【问题标题】:JQuery: mouseout event triggeringJQuery:鼠标悬停事件触发
【发布时间】:2012-07-23 09:16:40
【问题描述】:

我正在尝试使用 jQuery 模拟 mouseout 上的事件处理,但是在测试环境中未调用事件处理程序。可能是什么原因?

【问题讨论】:

  • 将您的代码发布到jsfiddle.net。我想解决你的问题:)

标签: jquery mouseover


【解决方案1】:

这样的?

$(document).ready(function() {
    $('#test, .comments').on('mouseenter', function() {
        $('.comments').stop(true,true).show('slow');
    });
    $('#test').on('mouseleave', function() {
        $('.comments').stop(true,true).hide('slow');
    });
})​;​

FIDDLE

也可以简写为:

$('#test').on('mouseenter mouseleave', function(e) {
    $('.comments').stop(true,true)[e.type==='mouseenter'?'show':'hide']('slow');
});

FIDDLE

【讨论】:

    【解决方案2】:

    我认为您正在寻找 mouseenter 和 mouseleave。

    它们只在悬停和退出时执行一次。

    http://api.jquery.com/mouseenter/

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-30
      • 1970-01-01
      • 1970-01-01
      • 2014-01-14
      • 2010-10-02
      • 1970-01-01
      相关资源
      最近更新 更多