我有一些 html/jQuery 用于实现一些选项卡式导航。选择新选项卡后,我需要将其 css 类设置为“事件”并将之前的选项卡 css 类更改为“非事件”。为此,我一直在我的 click
事件中使用以下代码:
$("ul.tabs li").removeClass("active"); //Remove any "active" class
$("ul.tabs li").addClass("inactive"); //Set all to "inactive"
$(this).removeClass("inactive"); //remove "inactive" from the item that was clicked
$(this).addClass("active"); //Add "active" class to the item that was clicked.
这行得通,但我很好奇是否有人找到了更简洁/更优雅的方法?
最佳答案
$("ul.tabs li").click(function(){
$(".active").removeClass("active").addClass("inactive");
$(this).removeClass("inactive").addClass("active");
});
工作示例位于:http://jsfiddle.net/4uMmc/
关于javascript - 有没有更优雅的方法将 css 应用于 "all elements but this one"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7003041/