首先说一下什么是mouseenter事件:
实际上就是鼠标从外面移到某个元素里面(触发了目标方法)后,鼠标再在里面移动不会重新触发目标方法。moueseleave同理。
本身ie系列浏览器是有onmouseenter这个事件定义的,但是firefox之类的浏览器没有这个,所以只能模拟。
以下提供完美模拟的方法:
//ele为目标元素,type为事件类型不用'on',func为事件响应函数 var addEvent=function(ele,type,func){ if(window.document.all) ele.attachEvent('on'+type,func);//ie系列直接添加执行 else{//ff if(type==='mouseenter') ele.addEventListener('mouseover',this.withoutChildFunction(func),false); else if(type==='mouseleave') ele.addEventListener('mouseout',this.withoutChildFunction(func),false); el.........[ More Detail ]