什么时候选择mouseover()和hover()函数?

2023-11-22

jQuery 之间有什么区别.mouseover() and .hover()功能?如果它们完全相同,为什么 jQuery 同时使用两者?


来自 jQuery 官方文档

  • .mouseover()
    将事件处理程序绑定到“mouseover”JavaScript 事件或触发器 元素上的该事件。

  • .hover()绑定一到两个处理程序 到匹配的元素,当鼠标指针移动时执行enters and leaves要素。

    Calling $(selector).hover(handlerIn, handlerOut)是以下形式的简写:$(selector).mouseenter(handlerIn).mouseleave(handlerOut);


  • .mouseenter()

    绑定一个事件处理程序,当鼠标进入某个元素时触发, 或在元素上触发该处理程序。

    mouseover当指针移动到子元素时触发 好吧,同时mouseenter仅当指针移入时触发 绑定元素。


这意味着什么

因为这,.mouseover() is not.hover(), 为了同样的原因.mouseover() is not.mouseenter().

$('selector').mouseover(over_function) // may fire multiple times

// enter and exit functions only called once per element per entry and exit
$('selector').hover(enter_function, exit_function) 
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

什么时候选择mouseover()和hover()函数? 的相关文章

随机推荐