js高手请进 div冒泡事件的疑惑 有加分

来源:百度知道 编辑:UC知道 时间:2024/09/28 09:28:24
<ul style="width:150px; height:40px; border:#006699 solid 1px; padding:10px;" onmouseout="hide(this)">
<li style="width:100px; height:20px; background:#0033CC;"></li>
</ul> 原意是:只有鼠标真正离开 ul 的时候才触发hide(this);事件,可现在鼠标进入 li 也会执行 hide(this) 有个说用event.cancelBubble=true 不管用,不知道是不是我用的不对,试过几个方法都不行。
我要的是解决办法啊,大哥!

<ul style="width:150px; height:40px; border:#006699 solid 1px; padding:10px;" onmouseout="hide(event)">//修改为event
<li style="width:100px; height:20px; background:#0033CC;"></li>
</ul>

<script type='text/javascript'>
function hide(ev){
var my_ul=document.getElementsByTagName('ul');
var e=ev||window.event;
var obj=e.toElement||e.relatedElement;
if(obj.nodeName!='LI' &&obj.nodeName!='UL')
alert('a');//用于测试
}
</script>

li不能单独使用,必须在UL内,所以UL就包括了LI的所有内容。指向LI就等同指向UL.
参考一下
http://wangpfsir.blog.163.com/blog/static/67963727200822732922356/

event.cancelBubble=true这个是IE的

stopPropagation 是FF的