Javascript 检查元素是否悬停在上方
我想检查元素是否悬停在上面。我得到这个错误:Javascript 检查元素是否悬停在上方,javascript,jquery,html,Javascript,Jquery,Html,我想检查元素是否悬停在上面。我得到这个错误: Syntax error, unrecognized expression: unsupported pseudo: hover 当我使用此代码时: $('.class').blur(function(){ if(!$(this).is(':hover')){ //element not being hovered over } }); 我也试过: $('.class').blur(function(){
Syntax error, unrecognized expression: unsupported pseudo: hover
当我使用此代码时:
$('.class').blur(function(){
if(!$(this).is(':hover')){
//element not being hovered over
}
});
我也试过:
$('.class').blur(function(){
if($(this+":hover").length === 0){
//element not being hovered over
}
});
这也不起作用。有没有其他方法可以做到这一点。谢谢 jQuery内置了此功能。
$(".class").mouseover(function(){
$(this).attr('checked',true);
});
});
您使用的是哪个jQuery版本?这是JQ1.9.x中的buggy。不过要注意,如果匹配集返回多个元素,这仍然不起作用,在任何jq版本的AFAIK中,但
if(!$(this).is(':hover'))
将在1.10.0 e.gI上工作。我使用1.9.x是因为我希望支持ie6/7/8升级到1.11.x(最新版本?),它仍然支持ie6/7/9,只有2.x分支删除了对real的支持?我会查一查的,谢谢
$(".class").hover(
function() {
// item is being hovered over
$(this).addClass('hover');
}, function() {
// item is no longer being hovered over
$(this).removeClass('hover');
}
);