Mouseleave 和 MouseOut 在 IE 11 中会触发两次



我正在尝试为我的一个div使用mouseleave函数。 我附加了两个不同的小提琴,一个使用jquery,另一个使用纯JavaScript。 jquery 示例使用 (document(.on,因为div 及其中的所有数据都是通过 Ajax 调用生成的。 这两个小提琴在Chrome中都可以正常工作,但是,在Internet Explorer中打开时,警报框会触发两次。 有趣的是,如果在 Internet Explorer 中将警报框更改为 console.log((,它只会写入控制台一次。

以前有人遇到过这个吗? 所需的行为是当鼠标离开div 时,警报框在 Internet Explorer 中触发一次。

https://jsfiddle.net/ttu1ouvz/

<div id="myTestDiv">
<p>
testing 
</p>
</div>
$(document).on("mouseleave", "#myTestDiv", function() {
alert("Your hovered over the test div");
});

https://jsfiddle.net/ttu1ouvz/4/

<!DOCTYPE html>
<html>
<body>
<div id="myTestDiv" onmouseout="mouseLeft(this)">
<p>
testing 
</p>
</div>
<script>
function mouseLeft(x){
alert("Your left the test div");
}
</script>
</body>
</html>

我已经使用.hover()解决了这个问题;

$(document).hover(function(){
alert("Your hovered over the test div");
}, function(){
alert("Your mouse leave from the test div");
});

https://api.jquery.com/hover/https://www.w3schools.com/jquery/event_hover.asp

最新更新