标签:style blog http java color strong
html
<ul id=”nav”>
<li><a href=”http://www.daqianduan.com/”>首页</a></li>
<li><a href=”http://www.daqianduan.com/category/html-css/”>HTML/CSS</a></li>
<li><a href=”http://www.daqianduan.com/category/javascript/”>JavaScript</a></li>
<li><a href=”http://www.daqianduan.com/category/seo/”>SEO</a></li>
<li><a href=”http://www.daqianduan.com/category/front-end/”>前端新闻</a></li>
</ul>
javascript(给当前页面指定导航加了.on的class)
$(function() {
var a1 = document.URL;
var a2 = $(“#nav a”);
for (var i = 0; i < a2.length; i++) {
if (a1.indexOf($(a2[i]).attr(“href”)) != -1) {
$(a2[i]).parent().addClass(“on”);
return;
}
}
$(a2[0]).parent().addClass(“on”);
})
css(根据自己的需求做相关调整)
#nav li{display:inline-block;float:left;text-align:center;height:36px;padding-left:4px;line-height:36px;background:url(http://img.daqianduan.com/ui/nav.gif) no-repeat right bottom;}
#nav li a{display:block;color:#777;padding:0 15px 0 10px;}
#nav li.on{font-weight:bold;background:url(http://img.daqianduan.com/ui/nav.gif) no-repeat 0 0;margin-left:-3px;}
#nav li.on a{background:url(http://img.daqianduan.com/ui/nav.gif) no-repeat right 0;}
javascript实现当前页导航激活,布布扣,bubuko.com
标签:style blog http java color strong
原文地址:http://www.cnblogs.com/songmz/p/3822628.html