html部分:
<ul class="navUl">
<li class="active"><a href="../">首页</a></li>
<li><a href="../tt/index.shtml">头条</a> </li>
<li> <a href="../zx/index.shtml">资讯</a></li>
<li><a href="../hdkd/index.shtml">活动看点</a></li>
<li><a href="../wzx/index.shtml">微资讯</a></li>
</ul>
js部分:
$(document).ready(function(){
$(".navUl li a").each(function(){
$this = $(this);
if($this[0].href==String(window.location)){
$(".navUl li").removeClass("active");
$this.parent().addClass("active"); //active表示被选中效果的类名
}
});
});