悬停时的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();
});
});