悬停时的jQuery无法正常工作 [英] Jquery on hover not functioning

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

问题描述

我正在更改自己的代码以与jQuery 1.8兼容,并且我一直无法使用此 hover .当我在 click 上使用相同的东西时,它起作用了.这是我的代码,谁能告诉我我要去哪里错了?

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();
  });
});

推荐答案

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

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.

来源: 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天全站免登陆