<li id="indexli"><a href="${base}/">首页</a></li> <script type="text/javascript"> function highlightIndex() { highlight("indexli"); } function highlight(id) { $("#" + id).addClass("liactive"); } </script>
var url = window.location.pathname; //默认为‘首页’index var current = ‘index‘; if (url.indexOf(‘/service‘) != -1) { current = ‘service‘; } else if (url.indexOf(‘/case‘) != -1) { current = ‘case‘; } else if (url.indexOf(‘/article‘) != -1) { current = ‘article‘; } else if (url.indexOf(‘/code‘) != -1) { current = ‘code‘; } else if (url.indexOf(‘/about‘) != -1) { current = ‘more‘; } else if (url.indexOf(‘/news‘) != -1) { current = ‘more‘; } else if (url.indexOf(‘/help‘) != -1) { current = ‘more‘; } else if (url.indexOf(‘/ask‘) != -1) { current = ‘ask‘; } else { current = ‘index‘; } for (var i = 0; i < navList.length; i++) { if (i == map[current]) { navList[i].className = ‘liactive‘; } else { navList[i].className = ‘‘; } }
原文地址:http://blog.csdn.net/fansunion/article/details/42583059