[英]How to mantain active a nav tab using jquery?
I'm using this js to put active a nav tab in my web page:我正在使用这个 js 在我的网页中激活一个导航选项卡:
$('a[href="' + this.location.pathname + '"]').parents('li,ul').addClass('active');
It works in the same level(secured/buyer_user/inbox/get/new_purchase)of the view, but if I change a location like secured/buyer_user/inbox/get/new_purchase the nav tab get inactive.它在视图的相同级别(secured/buyer_user/inbox/get/new_purchase)中工作,但是如果我更改诸如secured/buyer_user/inbox/get/new_purchase 之类的位置,则导航选项卡将处于非活动状态。
I have the following page structure:我有以下页面结构:
<nav class="navbar navbar-default navbar-fixed-top" id="nav" name="nav">
<div class="container-fluid">
<ul class="nav navbar-nav hover">
<li>...<li>
<ul>
</div>
</nav>
Any help would be great.任何帮助都会很棒。
Try this尝试这个
var loc = window.location.pathname;
$('#nav').find('a').each(function() {
$(this).toggleClass('active', $(this).attr('href') == loc);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.