下面我有我的代碼:加載到不同頁面時記住li活動狀態嗎?
<ul id="profileList" class="nav nav-list">
<li><a href="<?php echo base_url('user/signature')?>">修改個人簽名檔</a></li>
<li><a href="<?php echo base_url('user/location')?>">修改個人居住地</a></li>
<li><a href="<?php echo base_url('user/education')?>">修改個人學校專業</a></li>
</ul>
而且這裏的JS代碼:
<script type="text/javascript">
$(document).ready(function() {
// store url for current page as global variable
current_page = document.location.href
// apply selected states depending on current page
if (current_page.index(/signature/)) {
$("ul#profileList li:eq(0)").addClass('active');
} else if (current_page.match(/location/)) {
$("ul#profileList li:eq(1)").addClass('active');
} else if (current_page.match(/education/)) {
$("ul#profileList li:eq(2)").addClass('active');
} else { // don't mark any nav links as selected
$("ul#profileList li").removeClass('active');
};
});
</script>
當我點擊第二個和第三個項目裏,他們工作得很好。但是,當我點擊第一項, 該項目不會變得活躍。什麼是錯的,爲什麼?