我使用toggleClass().
看選擇哪個菜單選項的選擇菜單:如何查看哪個元素先被點擊?
$('.img1, .img2, .text1, .tex2').click(function() {
$(this).toggleClass('selected');
});
我的選擇菜單中的工作方式是,如果兩個元素具有類selected
然後會有些事情發生。例如:
if ($('.img1').hasClass('selected') && ('.text1').hasClass('selected')) {
// do something
}
這一切能夠完美,但是我想從吸取兩個imgs
或兩個texts
禁用用戶。我想要這樣做的方式只是將第一個選定的元素從選定的類中移除,並將第二個選定的元素保持選中狀態。例如:
if ($('.img1').hasClass('selected') && ('.img2').hasClass('selected')) {
// remove selected from the element that was first clicked and keep selected on the element that was clicked second
}
實現此目的的最佳方法是什麼?提前致謝。
爲什麼要投票? – iambriansreed 2012-07-31 18:30:55
我upvoted你的答案... – Jon 2012-07-31 18:33:09
我問你的問題上的DV。 – iambriansreed 2012-07-31 18:33:53