javascript onmouseout应用于儿童解雇的div [英] javascript onmouseout applied to div fired by children

查看:120
本文介绍了javascript onmouseout应用于儿童解雇的div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法通过谷歌找到解决方案,但我认为这将是一个常见的问题。我有一个div,我已经应用了一个onmouseout事件处理程序(该处理程序用于使用jquerysslideup功能滚动菜单,因为我希望在鼠标离开时隐藏菜单)。问题是,该div的子元素也会导致处理程序触发(我接受这是由于冒泡事件模型的性质而设计的)。现在我想知道的是什么是忽略由divs儿童触发的这些事件的最佳方法,并且只有当鼠标离开事件应用于div时才滚动菜单。

I'm having trouble finding a solution to this via google but I would have assumed it would be quite a common problem. I have a div which I have applied an onmouseout event handler to (the handler is used to roll a menu up using jquerys "slideup" function, as I would like the menu to be hidden when the mouse leaves). Problem is that the child elements of that div also cause the handler to fire (I accept that this is by design due to the nature of the bubbling event model). Now what I would like to know is what is the best way to ignore these events that are triggered by the divs children and only roll the menu up when the mouse leaves the div the event is applied to.

谢谢

推荐答案

您要查找的是mouseenter和mouseleave。

What you are looking for is mouseenter and mouseleave.

在这个链接中可以找到一个很好的例子(他们比较了mouseenter和mouseover)

A good example can be found at this link (they have compared both mouseenter and mouseover)

http://docs.jquery.com/Events/mouseover

一个博客条目

http://blogs.oracle .com / greimer / entry / mouse_over_out_versus_mouse

这篇关于javascript onmouseout应用于儿童解雇的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆