javascript - jQuery 的 mouseenter-mouseleave 与悬停事件之间的区别?

标签 javascript jquery difference

下面的代码片段有什么区别吗?

片段 1:

$("textarea").mouseenter(function() {
    alert("Hello mouseenter!");
});

$("textarea").mouseleave(function() {
    alert("Hello mouseleave!");
});

片段 2:

$("textarea").hover(function() {
    alert("Hello mouseenter!");
}, function() {
    alert("Hello mouseleave!");
});

我已经在 Chrome 和 Firefox 中检查了上面的代码片段,但是这两个片段的行为相同。但是,我想确定一下,mouseenter-mouseleave 和 hover 事件之间有什么区别吗?

最佳答案

它们之间没有区别... hover() 方法在内部注册了 mouseenter 和 mouseleave 处理程序...

悬停 - 代码

hover: function( fnOver, fnOut ) {
    return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
}

唯一的区别是如果你想使用事件委托(delegate),在那种情况下你不能使用 .hover()

关于javascript - jQuery 的 mouseenter-mouseleave 与悬停事件之间的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19585596/

相关文章:

javascript - 如何使用 Node js导出云Firestore中的动态嵌套集合数据?

javascript - 在 React Native 中的图像顶部创建一个旋转的文本横幅(梯形)

javascript - 使用 Grunt.js 运行 mocha 测试

javascript - jQuery 图像 slider 不适用于 jQuery 循环 (ASP.NET)

python - 计算 DataFrame Pandas 中 'times' 行之间的差异

python - 在不使用类的情况下减去 Python 中的两个列表

javascript - 无法使用react-router访问URL路径组件

javascript - 基思伍德 JQuery SVG : the SVG does not drawn in the div

javascript - 如果 div 因溢出而隐藏,则滚动

arrays - 最小化创建非递减数组成本的动态规划问题