如果某個元素沒有定義一個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