BLUE.NET

-------- 众里寻她千百度

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

又是一件惹人恼火的事,由于当前html元素(简称:父元素)和其内部html元素(简称:子元素)都有onmouseover和onmouseout事件,结果鼠标从父元素移动到子元素上也触发了onmouseout事件,但我并不希望发生这样的结果,我只是希望此时只触发子元素的onmouseover事件。

解决办法(IE) :
   onmouseover="if(!this.contains(event.fromElement))    mouseOverFun()"   
   onmouseout="if(!this.contains(event.toElement))    mouseOutFun()"   

meizz的非IE解决办法:
   if(typeof(HTMLElement)!="undefined"){   
       HTMLElement.prototype.contains    =    function(obj) {   
           while(obj!=null    &&    typeof(obj.tagName)!="undefind")   
           {if(obj==this)    return    true;    obj=obj.parentNode;}    return    false;   
       };   
   }

注:
   关键就是这个contains

posted on 2009-03-18 15:34  blue.net  阅读(339)  评论(0)    收藏  举报