如果某个元素没有定义一个css类,我想阻止两个事件被监视到一个元素(mouseenter和mouseleave是特定的)。Jquery不像预期的那样使用.not和.on
该系统的流动是
在文件准备好了,我想补充.selected到#menu_top_option_1元素
$("#menu_top_option_1").addClass("selected");
类没有为这两个事件传感器
$("#menu_top_option_1").not(".selected").on({ mouseenter: function(){ $(this).addClass("highlighted"); }, mouseleave: function(){ $(this).removeClass("highlighted"); } });
当发生点击事件时,我添加class .selec绑定到#menu_top_option_1元素。
$("#menu_top_option_1").click(function() { $("#menu_top_arrow_img").animate({left: position_menu_top_option_1+'px'}, 500); $(this).removeClass("highlighted"); $("#option_wrapper div.option").removeClass("selected"); $(this).addClass("selected"); });
的问题:如预期这不起作用。即使在添加.selected之后,元素仍然具有与分配.selected之前相同的悬停事件。除了#menu_top_option_1元素外,因为我怀疑它确实在文档准备好时添加了该类。
有什么建议吗?
谢谢!我现在意识到,我的做法非常蛮横。无论如何,我真的很感谢这个努力和完美的例子! – 2012-02-14 16:57:29