繁体   English   中英

jQuery:使选项卡处于活动状态

[英]JQuery: Making a tab active

在此网站上: 链接文字

如何找到一个元素并删除所有class = selected并将其添加到正确的链接? 这样,当单击历史记录,模型和类似链接时,它们看起来将被选中。

下面的代码可以解决您的问题。

// when clicking a link inside the sub-navigation list
$('#sub-navigation a').click(function(){ 
    // first remove the selected class from the active one
    $('#sub-navigation li.selected').removeClass('selected');
    // then find the parent li of the clicked element and add the selected class
    $(this).parents('li').addClass('selected');
});

(它已在您的示例页面上经过测试,并且可以按预期工作。)

$("a").click(function(e) {
$("a.selected").removeClass("selected");
$(this).addClass("selected");
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM