【问题标题】:jquery remove add classes on hoverjquery在悬停时删除添加类
【发布时间】:2011-04-29 19:57:25
【问题描述】:

好的,所以我找到了一个代码,它似乎正在工作,但我需要在该代码中添加一些内容以防止它在我将鼠标悬停在其子菜单/子菜单元素上时触发,但当我将鼠标悬停在其上时仍需要触发其他项目或其他项目子菜单的这是当前脚本

$(document).ready(function() {     
   $("#navbar li:hover, #navbar li:sfhover").hover(function(){     
       $('#navbar .current-menu-parent, #navbar li.current-menu-item').addClass("non-ahover");    
   },     
   function(){    
       $('#navbar li.current-menu-parent, #navbar li.current-menu-item').removeClass("non-ahover");     
    });
}); 

所以我当前的活动菜单将具有 .current-menu-parent 或 .current-menu-item。我的子菜单从父级的

  • 类中的
      类开始,子菜单类是
  • 【问题讨论】:

      标签: jquery class call


      【解决方案1】:
      1. 将事件处理程序绑定到子项
      2. 让该处理程序调用 stopPropagation()

      http://api.jquery.com/event.stopPropagation/

      【讨论】:

      • 你认为你可以将它添加到我的代码中吗?我对这一切都很陌生,在过去的几个小时甚至几天里,我在这个项目上学到了很多
      • $(".submenu").hover(function(event){ event.stopPropagation(); });
      • 好的,如果在 where abouts 里面,它会进入当前脚本还是外部
      • 在您的示例中传递给 $(document).ready() 的匿名函数中
      • 好的,所以我一直在尝试这几种不同的方式,无论是我还是代码,但我无法弄清楚我已经把它放在了 **(HERE)** $(document).ready(function() { 之前和之后 @987654323 之后的 4 个位置@ 以及在$('#navbar .current-menu-parent, #navbar li.current-menu-item').addClass("non-ahover"); }, **(HERE)**$('#navbar li.current-menu-parent, #navbar li.current-menu-item').removeClass("non-ahover"); **(HERE)** 之后它只是不起作用,父级高于子菜单,所以我不确定这是否重要
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-05-16
      • 1970-01-01
      • 2010-12-30
      • 1970-01-01
      • 1970-01-01
      • 2013-05-05
      • 1970-01-01
      相关资源
      最近更新 更多