又是一件惹人恼火的事,由于当前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