【发布时间】:2012-08-23 21:43:47
【问题描述】:
所以我尝试使用 .hover() 方法,该方法仅在悬停的元素没有特定类时才执行某些操作。如果我将类添加到 HTML 中的相关元素,它工作正常。但是假设我有一个使用 .addClass() 使用 jQuery 添加类的单击事件。然后 hover() 方法会忽略已添加的类。够啰嗦了。这是代码。
$('.foo:not(.bar)').hover(function() {
someCrap(); //when hovering a over .foo that doesn't also have the class .bar, do someCrap
}
$('.foo').click(function(){
$(this).addClass('bar'); //after the element .foo gets another class .bar, the hover event written earlier continues to work, WTF
})
男生女生有什么想法吗?
【问题讨论】:
标签: javascript jquery addclass jquery-hover