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

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")});
}

posted @ 2016-08-24 10:13  huerge  阅读(400)  评论(0编辑  收藏  举报