jquery悬停无法正常工作 [英] Jquery on hover not working

查看:106
本文介绍了jquery悬停无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将代码更改为与jQuery 1.8兼容,而且我坚持使用 hover ,这不起作用。当我对使用同样的东西时,点击它就起作用了。这里是我的代码,任何人都可以告诉我哪里出错了?

  $(document).on('hover','.top-level',function(event){
$(this).find('。actionfcnt')。show();
$(this).find('。dropfcnt')。show();
},function(){$隐藏('blind',function(){
$('。actionfcnt')。hide();
});
$(this).find('。dropfcnt')。 b $ b});


解决方案

自jQuery 1.8弃用:名称hover用作字符串mouseenter mouseleave的简写。它为这两个事件附加一个事件处理程序,处理程序必须检查event.type以确定该事件是mouseenter还是mouseleave。 请勿将悬停伪事件名称与接受一个或两个函数的.hover()方法混淆。

来源: http://api.jquery.com/on/#additional-notes

几乎可以说这一切,你不能使用悬停为:



<$ p $ ('mouseenter','。top-level',function(event){
$(this).find('。actionfcnt')。show( );
$(this).find('。dropfcnt')。show();
})。on('mouseleave','。top-level',function(){$ b $隐藏('blind',function(){
$('。actionfcnt')。hide();
}); $ b $(this.find('。dropfcnt')。 b});


I'm changing my codes to be compatible with jQuery 1.8 and I'm stuck with this hover which doesn't work. When I used then same thing with a click it worked. Here is my code, can anyone tell me where I'm going wrong?

$(document).on('hover', '.top-level', function (event) {
  $(this).find('.actionfcnt').show();
  $(this).find('.dropfcnt').show();
}, function () {
  $(this).find('.dropfcnt').hide('blind', function () {
    $('.actionfcnt').hide();
  });
});

解决方案

Deprecated as of jQuery 1.8: The name "hover" used as a shorthand for the string "mouseenter mouseleave". It attaches a single event handler for those two events, and the handler must examine event.type to determine whether the event is mouseenter or mouseleave. Do not confuse the "hover" pseudo-event-name with the .hover() method, which accepts one or two functions.

Source: http://api.jquery.com/on/#additional-notes

That pretty much says it all, you cant use "hover" for that:

$(document).on('mouseenter','.top-level', function (event) {
    $( this ).find('.actionfcnt').show();
    $( this ).find('.dropfcnt').show();
}).on('mouseleave','.top-level',  function(){
    $( this ).find('.dropfcnt').hide('blind', function(){
        $('.actionfcnt').hide();
    });
});

这篇关于jquery悬停无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆