【发布时间】:2020-07-16 11:10:34
【问题描述】:
我正在尝试在导航中添加活动类。 我用了这篇文章。 Add Active Navigation Class Based on 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');
}
})
})
效果很好。 但我的问题是在这种情况下。
/blog, /blogAds
如果 url 是 /blog, 活动类添加到两个导航项。
有什么解决办法吗?
【问题讨论】:
标签: javascript jquery laravel bootstrap-4 navigation