jquery - jQuery 语法错误?

标签 jquery css

基于堆栈溢出帖子的答案: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 examine event.type to determine whether the event is mouseenter or mouseleave. 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/

相关文章:

改变元素在滚动条上位置的 jQuery 代码

javascript - 如何使元素在javascript中的mouseout事件后重置其位置

javascript - styled-components:扩展样式和改变元素类型

html - 在 IE11 中响应

javascript - 如何将 "select"事件附加到页面上的每个文本节点?有没有更好的办法?

javascript - 如何获取对象的键名

javascript - setTimeout() 返回未捕获的类型错误

javascript - 有没有办法在 jquery 中到达 parent 的 sibling ?

jQueryUI 自动完成 - 当没有返回结果时

html - 如何在同一包含元素中以不同方式内联对齐文本 block ?