根据href给当前导航添加样式

时间:2021-04-02 05:13:49

var href = window.location.href.split('/')[window.location.href.split('/').length-1].substr(0,20);
if(href.length > 0){
  $(function(){
    $("ul.nav a[href^='"+href+"']").parent().attr("class","active");
  });
}else{
  $(function(){$("ul.nav a:first[href^='index']").parent().attr("class","active")});
}