我想讓我的網站菜單在用戶瀏覽頁面時突出顯示/激活,但下面的代碼不起作用。Jquery突出顯示活動菜單
有人可以檢查發生了什麼問題嗎?謝謝。
<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>
你的條件是錯誤的,你需要使用正則表達式來檢查它 – 2013-02-26 03:42:11