jquery 只在 Debug模式下工作

标签 jquery css

我有一个非常简单的 jQuery 代码片段。

看起来像这样:

$(document).ready(function() {                
   jQuery('.mh_img_box2').closest('.mh_img_box1').hover(function () {
       console.log("click");
       jQuery(this).find('.sp_product-note, .sp_product-note2 ').show();
       jQuery(this).addClass('hover-image');
       console.log("click");
   })

   jQuery('.mh_img_box2').closest('.mh_img_box1').mouseleave(function (){
       jQuery('.sp_product-note, .sp_product-note2').hide();
       jQuery(this).removeClass('hover-image');
   })
});

使用这段代码,我只想在鼠标悬停在相应元素上时显示悬停文本。

不幸的是,它只能在 Debug模式下工作。

您可以在此处查看该站点:

http://v4.machhoerndl-kaffee.de/sw/

感谢您的帮助。

最佳答案

您需要将代码压缩到单个 hover 事件处理程序代码中,如下所示:-

$(document).ready(function(){
    $('.mh_img_box1').hover(function () {
        $(this).find('.sp_product-note, .sp_product-note2 ').show();
        $(this).addClass('hover-image');
    },function(){
        $(this).find('.sp_product-note, .sp_product-note2 ').hide();
        $(this).removeClass('hover-image');
    });
});

注意:- 我已经在您的网站上检查了这段代码

1.在控制台中添加代码以检查:- https://prnt.sc/j52qtx

2.现在我将鼠标悬停在框上:- https://prnt.sc/j52r45

3.现在,当我将鼠标悬停在框外时:- https://prnt.sc/j52rae

关于jquery 只在 Debug模式下工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49828162/

相关文章:

css - 遍历css语法错误和困惑

html - 当有空间时,Bootstrap 列必须移到一边

javascript - FancyBox Jquery Null 错误 - 奇怪的问题

javascript - 一个关于jquery闭包的简单问题

javascript - jQuery - 如何向下滑动正文附加数据?

css - 创建一个 div 正方形,并使用 less 将其相应地居中于视口(viewport)

jquery - 如何在移动Web应用程序中使用asp.net制作手机的通话功能

javascript - 显示/隐藏选项卡箭头以在溢出时导航其他选项卡

jQuery SlideDown 子菜单上边距

css - 在 CSS HTML 中对齐翻转卡片