gpt4 book ai didi

javascript - 如何在纯 JavaScript 中检测 mousein 和 mouseleave?

转载 作者:搜寻专家 更新时间:2023-11-01 04:09:59 26 4
gpt4 key购买 nike

由于各种原因,我无法在这部分项目中使用jQuery。所以我需要在 Vanilla js 中检测到这一点。我试过这个但它不起作用:

http://jsfiddle.net/qHfJD/

var myDiv = document.getElementById('foo');

myDiv.onmouseenter = function() {
alert('entered');
}

myDiv.onmouseleave = function() {
alert('left');
}

最佳答案

myDiv.onmouseover = function(event) {
if (this != event.currentTarget) { return false; }
// mouse enter ...
}
myDiv.onmouseout = function(event) {
if (this != event.currentTarget) { return false; }
// mouse leave ...
}

关于javascript - 如何在纯 JavaScript 中检测 mousein 和 mouseleave?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15280531/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com