mouseover和mouseenter事件有什么区别? [英] What is the difference between the mouseover and mouseenter events?

查看:113
本文介绍了mouseover和mouseenter事件有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直使用mouseover事件,但是在阅读jquery文档时,我发现了mouseenter。他们似乎功能完全一样。两者之间有区别吗?如果是这样,我应该用它们吗? (也适用于mouseout vs mouseleave)

I have always used the mouseover event, but while reading the jquery documentation I found mouseenter. They seem to function exactly the same. Is there a difference between the two, and if so when should I use them? (Also applies for mouseout vs mouseleave)

推荐答案

您可以尝试这里在jQuery文档页面。这是一个很好的小型交互式演示,使其非常清晰,您可以自己看到。

You can try it out here on the jQuery doc page. It's a nice little, interactive demo that makes it very clear and you can actually see for yourself.

简而言之,您会发现鼠标悬停事件发生在元素,当你结束它 - 来自它的孩子或父元素,但鼠标输入事件只发生在鼠标从外部元素移动到这个元素。

In short, you'll notice that a mouse over event occurs on an element when you are over it - coming from either its child OR parent element, but a mouse enter event only occurs when the mouse moves from outside this element to this element.

或者作为 mouseover() docs 将它:

Or as the mouseover() docs put it:


[ .mouseover()]可能会导致许多头痛,由于事件冒泡。例如,当本示例中鼠标指针移动到Inner元素上时,鼠标悬停事件将被发送到该元素,然后将其移至外部。这可以触发我们绑定的鼠标悬停处理程序不合时宜。请参阅 .mouseenter()的讨论,以获得有用的替代方案。

[.mouseover()] can cause many headaches due to event bubbling. For instance, when the mouse pointer moves over the Inner element in this example, a mouseover event will be sent to that, then trickle up to Outer. This can trigger our bound mouseover handler at inopportune times. See the discussion for .mouseenter() for a useful alternative.

这篇关于mouseover和mouseenter事件有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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