$(function(){ var href = window.location.href.split('/')[window.location.href.split('/').length-1].substr(0,4); if(href.length > 0){ $(function(){ $("ul.nav a:first[href^='"+href+"']").attr("class","on"); if($("ul.nav a:first[href^='"+href+"']").size() == 0){ $("ul.nav a:first[href^='index']").attr("class","on"); } }); }else{ $(function(){$("ul.nav a:first[href^='index']").attr("class","on")}); }})
截取URL最后4位对比导航中A标签链接相同的元素加on样式