请看
http://xuganggogo.iteye.com/admin/blogs/538476,有更简单解决方案。
假设一个div中有若干个子元素,在此div上设置onMouseOut()触发事件。会发现,鼠标经过此div的子元素时,onMouseOut()事件也同样会触发。这并不是我们想要的结果,应该做如下修改。
if (event.toElement) { if (!this.contains(event.toElement)) { alert('ok'); } }
在这里this是最外层的元素。
event.fromElement指向触发onmouseover和onmouseout事件时鼠标离开的元素;
event.toElement指向触发onmouseover和onmouseout事件时鼠标进入的元素。
在IE下,以上方法可以通过。