mouseout触发内层问题的解决方法

来源:互联网 发布:js遍历object对象 编辑:程序博客网 时间:2024/06/06 16:58

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
ul {
 border:1px solid red; padding:10px;
 zoom:1; /* 触发IE layout */
}
ul li{
 line-height:30px;border:1px solid blue; margin:10px
}
</style>
<script type="text/javascript">
window.onload = function(){
 var h=document.getElementById('hide');
 h.onmouseout=function(e) {
  var e = e || window.event, relatedTarget = e.toElement || e.relatedTarget;
  while(relatedTarget && relatedTarget != this)
   relatedTarget = relatedTarget.parentNode;
  if(!relatedTarget)
   alert("a");
 }
}
</script>
</head>
<body>
<ul  id="hide1">
 <li>11111111111</li>
    <li>11111111111</li>
    <li>11111111111</li>
    <li>11111111111</li>
</ul>

<div id="hide">想在ul移出才alert 而不是在li之间也alert 应该怎么写呢~~谢谢</div>
</body>
</html>

原创粉丝点击