开发者

I want to make my menu selected everytime it is clicked and changes the pages with selected menu

I have this jquery script:

<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>

and css is as follows

 .selectedli a {background: #3a73ba; color:#fff; cursor:default;} 

and menu is written as

<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>

      </u开发者_JAVA百科l>
    </div>

but when I click the link and navigate to "inner_index.php" the first li is selected whereas I want to select the second li. What should I do?


you can use

:second 

or

:eq(1)

So

$(".navigation li:first").addClass("selectedli").show(); //Activate first tab

will become

$(".navigation second").addClass("selectedli").show(); //Activate first tab
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜