[英]Add Active Navigation Class Based On Url for similar url
I am trying to add active class in navigation.我正在尝试在导航中添加活动 class 。 I used this article.
我用了这篇文章。 Add Active Navigation Class Based on URL
添加主动导航 Class 基于 URL
$(function(){
var current = location.pathname;
$('#nav li a').each(function(){
var $this = $(this);
// if the current path is like this link, make it active
if($this.attr('href').indexOf(current) !== -1){
$this.addClass('active');
}
})
})
It worked well.它运作良好。 But my issue is in this case.
但我的问题是在这种情况下。
/blog, /blogAds
If url is /blog,
active class added to both nav items.如果 url 是
/blog,
则将活动 class 添加到两个导航项。 Is there any solution for it?有什么解决办法吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.