【发布时间】:2010-11-01 14:03:26
【问题描述】:
嗨: 当我将 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移出,你会得到两个警告窗口,我只想要一个。
那么如何解决呢?
【问题讨论】:
标签: javascript mouseout