Was*_* A. 11 jquery if-statement hover
$('.xx').mouseenter(function(){
if($(this).is(':hover'))
alert('d');
else
alert('f');
});
Run Code Online (Sandbox Code Playgroud)
这是我的代码,它应该警告'd',但每次它警告'f'这里有什么错误
mat*_*uds 31
function idIsHovered(id){
return $("#" + id + ":hover").length > 0;
}
Run Code Online (Sandbox Code Playgroud)
http://jsfiddle.net/mathheadinclouds/V342R/
正如Frederic所说:hover是CSS的一部分,并不是jQuery中的选择器.
有关替代解决方案,请参阅如何检查鼠标是否在jQuery中的元素上?
将mouseout上的超时设置为淡出并将返回值存储到对象中的数据.然后onmouseover,如果数据中有值,则取消超时.
删除淡出回调的数据.