在IE里有onmouseleave和onmouseenter, 而对于要兼容各大浏览器的Web开发人员来说还是一件头疼的事。 虽然网上已经有针对Mozilla Firefox的一些计策,但代码量也是不容乐观的。 想寻求比较好的解决方案,于是就翻遍了国内的大小网站,终一无所获,不得不硬着头皮去读国外网站,结果是理想的,因为W3C里有relatedTarget,于是就有了下边的解决方案: 复制代码 代码如下:function isMouseLeaveOrEnter(e, handler) { if (e.type != 'mouseout' && e.type != 'mouseover') return false; var reltg = e.relatedTarget ? e.relatedTarget : e.type == 'mouseout' ? e.toElement : e.fromElement; while (reltg && reltg != handler) reltg = reltg.parentNode; return (reltg != handler); }在onmouseover和onmouseout里做如上判断。 作者:lxsgoodluck
推荐阅读
IE和FireFox(FF)中js和css的不同
在IE和FireFox(FF)中js和css的不同 css: 1. ul标签中FF中有个padding值,却没有margin值,而在IE中正好相反 解决办法:将ul的padding和margin都设为0(也可以不是0)如:padding:0;margin:0;list-style:none; js: 1. >>>详细阅读
本文标题:javascript mouseover、mouseout停止事件冒泡的解决方案
地址:http://www.17bianji.com/kaifa2/JS/28840.html
1/2 1