手风琴菜单中的活动状态

时间:2012-05-02 11:05:37

标签: javascript jquery html css

我在我的网页上使用了手风琴菜单,该网页是从这个网站http://www.designchemical.com/lab/jquery-vertical-accordion-menu-plugin/examples/中提取的。如果我点击主菜单,则会打开相应的子菜单。如果我单击子菜单,它会重定向到链接页面。但该菜单不在该页面的opened state中。这是我的问题。我该如何纠正?

我使用的内部脚本是

<script type="text/javascript">
$(document).ready(function($){
    $('#accordion-3').dcAccordion({
        eventType: 'click',
        autoClose: false,
        saveState: false,
        disableLink: false,
        showCount: false,
        speed: 'slow'
    });
});
</script>

1 个答案:

答案 0 :(得分:0)

将当前状态保存在cookie中

setCookie('state',$( "#accordion-3" ).accordion('option','active'));

重定向后的另一页

$('#accordion-3').dcAccordion({
        active:getCookie('state'), /****activating the current state***/
        eventType: 'click',
        autoClose: false,
        disableLink: false,
        showCount: false,
        speed: 'slow'
    });

/**cookie functionalities***/
function deleteCookie(name) {
        setCookie(name,"",-1);
    }
    function setCookie(name,value,days) {
        if (days) {
            var date = new Date();
            date.setTime(date.getTime()+(days*24*60*60*1000));
            var expires = "; expires="+date.toGMTString();
        }
        else expires = "";
        document.cookie = name+"="+value+expires+"; path=/";
    }
    function getCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++) {
            var c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1,c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return null;
    }