开发者

jquery accordion open a section

I'm trying to implement a state-saving accordion menu...

So far I have this:

$(document).ready(function () {
    $("#accordionMenu").accordion({
        alwaysOpen: false,
        animated: true,
        autoHeight: false,
        collapsible: true,
        icons: false,
        navigation: true
    });
        var toOpen = <%= MySessionInfo.Current.MyMenu %>;
        if(toOpen != -1){
            alert("it should open: " +toOpen);
            $("#accordionMenu").accordion("active", toOpen);
            alert("active is : " + $("#accordionMenu").accordion("option", "active"));
        }

        $("#accordionMenu").click(function (){
            var activate = $("#accordionMenu").accordion("option", "active");
            if (activate != false) {
         开发者_运维百科       $.getJSON("/Account/SetMenu", { CurrentMenu: activate }, function (j) {});
            }
        });
    });

It sets the correct index and it shows the right message "it should open X", where X is the expected value. However, it doesn't keeps open that section and after setting the "active" value, the "active is: Y" shows "false" all the time.

what's happening?


You got a typo. It should be

$('...').accordion('activate', index);

Found at http://jqueryui.com/demos/accordion/#method-activate


You should do either:

$("#accordionMenu").accordion({active:toOpen});

or

$("#accordionMenu").accordion("activate", toOpen);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜