我有一些html/jQuery代码,用于实现选项卡导航。当选择一个新的选项卡时,我需要将其css类设置为"active",并将以前的选项卡的css类更改为"inactive"。为了做到这一点,在我的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.
这个方法可以实现,但我想知道是否有更简洁/更优雅的方式来实现这个目标?
$().removeClass().addClass()
。 - gion_13