gpt4 book ai didi

JavaScript:JavaScript 中的 mouseenter 事件?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:34:40 24 4
gpt4 key购买 nike

javascript 中是否有鼠标进入事件(请仅使用 JavaScript,不使用 jQuery)?

当我这样做时,它没有任何反应。

window.onload = initAll;
function initAll(){
if(window.addEventListener){
document.getElementById('container').addEventListener( 'mouseenter', freeze , false);
}
}

function freeze(){
console.log("mouse entered")
}

有人可以解释一下“mouseenter”和“mouseover”之间的区别吗? “mouseover”是“mouseenter”的替代品吗?

感谢帮助!

最佳答案

不要为 onmouseenter 而烦恼,因为 this page说明它特定于 IE。

...Both onmouseenter and onmouseover fire when the mouse enters the boundary of an element. However, onmouseenter doesn't fire again (does not bubble) if the mouse enters a child element within this first element.

试试这个 onmouseover:

yourObject.onmouseover=function()
{
//SomeJavaScriptCode
};

检查 this page有关 javascript 鼠标事件的一些有用信息。

关于JavaScript:JavaScript 中的 mouseenter 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16713871/

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