嗨:当我向父元素添加 mouseout 事件时,似乎它的所有子元素也都添加了此事件,如果事件是鼠标单击等,则效果很好。
但是对于 mouseout 事件,这会导致一些意想不到的结果。
看看这个例子:
<html>
<head>
<script type="text/javascript">
function init(){
document.getElementById('par').onmouseout=function(){alert('mouse out')};
}
</script>
</head>
<body onload='init()'>
<div id="par" style="width:400px;height:300px">
<div style="background-color:red;width:100%;height:150px"></div>
<div style="background-color:black;width:100%;height:150px"></div>
</div>
</body>
</html>
请从红色 div 移到黑色 div,然后移出黑色 div,然后你会得到两个警报窗口,我只想要一个。
那么如何解决呢?