当用户浏览页面时,我想让我的站点菜单突出显示/激活,但是下面的代码不起作用。
有人可以检查发生了什么问题吗?谢谢。
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
// this will get the full URL at the address bar
var url = window.location.href;
// passes on every "a" tag
$("#nav_main a").each(function() {
// checks if its the same on the address bar
if(url == (this.href)) {
$(this).closest("li").addClass("active");
}
});
});
</script>
<style type="text/css">
.active{
color:#f93;
}
</style>
<div id="nav_main">
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="aboutFrontend.php">About</a></li>
<li><a href="subscribeFrontend.php">Subscribe</a></li>
<li><a href="newsFrontend.php">News</a></li>
<li><a href="magFrontend.php">Mag</a></li>
<li><a href="contactFrontend.php">Contact</a></li>
</ul>
</div>