jquery 手风琴打开一个部分

发布于 2024-10-15 18:05:06 字数 987 浏览 5 评论 0原文

我正在尝试实现一个状态保存手风琴菜单...

到目前为止我有这个:

$(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) {});
            }
        });
    });

它设置正确的索引并显示正确的消息“它应该打开 X”,其中 X 是预期值。 但是,它不会保持该部分打开,并且在设置“活动”值后,“活动是:Y”始终显示“假”。

发生了什么事?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

天邊彩虹 2024-10-22 18:05:06

你有一个错字。它应该

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

位于 http://jqueryui.com/demos/accordion/#method-activate< /a>

You got a typo. It should be

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

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

财迷小姐 2024-10-22 18:05:06

您应该执行以下任一操作:

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

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

You should do either:

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

or

$("#accordionMenu").accordion("activate", toOpen);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文