how to keep track of accordion(in masterpage) open status after page navigation?

前端 未结 1 1625
感动是毒
感动是毒 2020-12-22 13:11

i am using jquery accordion as a menu in asp.net Masterpage.

This is jquery

$(document).ready(function() {
    $(\".header\").click(function() {
             


        
相关标签:
1条回答
  • 2020-12-22 13:28

    If you add id attributes to your headers:

    <p class="header" id="header-1">Header-1</p>
        <div class="menu_body">
            <a href="page1.aspx">Link-1</a>
        </div>
    

    Then you can pull the id out in your handler and use jquery.cookie to track the open panel in a cookie:

    $(".header").click(function() {
        var $this = $(this);
        if(!$this.hasClass('display'))
            $.cookie('open_panel', this.id);
        $this.toggleClass("display");
        $this.next("div .menu_body").slideToggle(500);
    });
    

    You'd need to play with the storage format for open_panel a bit if you want to have multiple panels open at one time but a simple CSV list would probably suffice; I'll leave that part as an exercise for the reader. You'd also want to check the cookie when the page loads and open the appropriate panels.

    You could also keep track of the cookie's value on the server if you wanted to keep the setting around as part of the user's account preferences.

    0 讨论(0)
提交回复
热议问题