gpt4 book ai didi

javascript - 为什么当子元素悬停时会触发 mouseout?

转载 作者:行者123 更新时间:2023-11-29 18:35:06 26 4
gpt4 key购买 nike

奇怪的是当鼠标光标越过子节点时会触发 mouseout 事件。为什么光标还没有离开父节点会出现这种情况呢?请考虑这一点:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title></title>
<script type='text/javascript'>

function someFunc(obj) {
document.getElementById('info').innerHTML = 'over';
document.getElementById('info3').innerHTML = 'over';

obj.onmouseout = function() {
document.getElementById('info2').innerHTML = 'out';
document.getElementById('info3').innerHTML = 'out';
}

if (!obj.theChild) {
var theChild = document.createElement('div');
theChild.style.position = 'relative';
theChild.style.left = '20px';
theChild.style.top = '20px';
theChild.style.width = '40px';
theChild.style.height = '40px';
theChild.style.background = '#eeee00';
obj.theChild = theChild;
obj.appendChild(theChild);
}
}

</script>
<head>
<body>

<span id="info"></span> <span id="info2"></span> <span id="info3"></span>

<div style="position:absolute;top:100px;left:100px;width:100px;height:100px;background:#000000;" onmouseover="someFunc(this);"></div>

</body>
</html>

最佳答案

关于javascript - 为什么当子元素悬停时会触发 mouseout?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4093416/

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