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")});
}
转载于:https://www.cnblogs.com/hubl/p/5801786.html