gpt4 book ai didi

javascript - 有没有更优雅的方法将 css 应用于 "all elements but this one"?

转载 作者:技术小花猫 更新时间:2023-10-29 12:04:00 26 4
gpt4 key购买 nike

我有一些 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com