基于堆栈溢出帖子的答案:Change background color on mouseover and remove it after mouseout
下面的代码应该将CSS设置为显示:block;悬停并显示时:无;当它们悬停时。
谁能看出下面的代码有什么问题吗? (没有发生控制台错误)我基本上是在尝试为自己制作一个简单的工具提示。
$(function () {
$(document).on('hover', '.inter [class]', function () {
$('._22t').css({
'display': 'block'
});
}, function () {
$('._22t').css({
'display': 'none'
});
});
});
最佳答案
on
不接受 2 个回调函数,除此之外,您不能将 hover
伪事件名称与 on
方法一起使用:
Deprecated in jQuery 1.8, removed in 1.9: The name "hover" used as a shorthand for the string
"mouseenter mouseleave"
. It attaches a single event handler for those two events, and the handler must examineevent.type
to determine whether the event ismouseenter
ormouseleave
. Do not confuse the "hover" pseudo-event-name with the.hover()
method, which accepts one or two functions.
$(document).on('mouseenter mouseleave', '.inter [class]', function(event) {
$('._22t').toggle(event.type === 'mouseenter');
});
关于jquery - jQuery 语法错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16727077/