我有这个jquery脚本:
<script type="text/javascript">
$(document).ready(function() {
//Default Action
$(".navigation li:first").addClass("selectedli").show(); //Activate first tab
//On Click Event
$(".navigation li").click(function() {
$(".navigation li").removeClass("selectedli"); //Remove any "active" class
$(this).addClass("selectedli"); //Add "active" class to selected tab
});
});
</script>
和css如下
.selectedli a {background: #3a73ba; color:#fff; cursor:default;}
,菜单写为
<div class="navigation">
<ul>
<!--<li><a href="#" onmouseover="mopen('m1')" onmouseout="mclosetime()">About Us</a>
<div id="m1" onmouseover="mcancelclosetime()" onmouseout="mclosetime()"> <a href="inner_page.html">Member Profile</a> <a href="inner_page.html">Message from MD</a> <a href="inner_page.html">History</a> </div>
</li>-->
<li class="selectedli"><a href="#">Home</a></li>
<li><a href="inner_index.php">2nd Page</a></li>
<li><a href="inner2.php">Third Page</a></li>
</ul>
</div>
但是当我点击链接并导航到“inner_index.php”时,第一个li
被选中,而我想选择第二个li
。我该怎么办?
答案 0 :(得分:0)
你可以使用
:second
或
:eq(1)
所以
$(".navigation li:first").addClass("selectedli").show(); //Activate first tab
将成为
$(".navigation second").addClass("selectedli").show(); //Activate first tab