jQuery 手风琴在加载时关闭

发布于 2024-10-17 19:57:44 字数 257 浏览 3 评论 0原文

如何在页面加载时关闭手风琴小部件?这是我正在使用的代码:

//Accordion
    $( ".accordion" ).accordion({
        autoHeight: false,
        navigation: true,
        collapsible: true,
        active: false
    });

另外,它可能不重要,但手风琴 div 位于对话框 div 内。

How can I get the accordion widget to be closed when the page loads? This is the code I'm using:

//Accordion
    $( ".accordion" ).accordion({
        autoHeight: false,
        navigation: true,
        collapsible: true,
        active: false
    });

Also, it may be unimportant but the accordion divs are inside dialog divs.

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

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

发布评论

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

评论(2

饭团 2024-10-24 19:57:44

active 选项设置为 false 应该(根据 docs)导致菜单在页面加载时折叠(尽管它特别要求 collapsible: true (您已经拥有)。

如果这尚未位于 $(window).load()$(document).ready() 中,则需要将其包装在其中之一中;它如此包装然后没有演示(也许JS Fiddle,或JS Bin?)很难表明可能发生的情况或出现的问题。JavaScript

的其余部分(除了调用 .accordion() 正在执行吗?如果没有,可能会在某个地方出现 JS 错误。可能值得通过 JS Lint 运行它。 可以肯定。

The active option being set to false should (according to the docs) cause the menu to be collapsed on page-load (though it specifically requires collapsible: true (which you already have).

If this isn't already in a $(window).load() or $(document).ready() then it needs to be wrapped in one of those; if it is so wrapped then without a demo (perhaps JS Fiddle, or JS Bin?) it's difficult to suggest what might be happening, or going wrong.

Is the remainder of the JavaScript (beyond the call to .accordion() being executed? If not there might be a JS error, somewhere. It might be worth running it through JS Lint to be sure.

扛起拖把扫天下 2024-10-24 19:57:44

索引值可以是布尔值或整数

<script language="javascript" type="text/javascript">
    $(function () {
        var activeIndex = parseInt($('#<%=AccordionIndexHidden.ClientID %>').val());
        if (activeIndex < 0) 
            activeIndex = false;
        $("#accordion").accordion({
            autoHeight: false,
            event: "mousedown",
            active: activeIndex,
            change: function (event, ui) {
                var index = $(this).children('h3').index(ui.newHeader);
                $('#<%=AccordionIndexHidden.ClientID %>').val(index);
            }
        });
    });


</script>

请记住从小于 0 的索引开始

    <asp:HiddenField ID="AccordionIndexHidden" runat="server" Value="-1" />

仅供参考,隐藏字段用于在回发之间保持打开的手风琴

The index value can be boolean or integer

<script language="javascript" type="text/javascript">
    $(function () {
        var activeIndex = parseInt($('#<%=AccordionIndexHidden.ClientID %>').val());
        if (activeIndex < 0) 
            activeIndex = false;
        $("#accordion").accordion({
            autoHeight: false,
            event: "mousedown",
            active: activeIndex,
            change: function (event, ui) {
                var index = $(this).children('h3').index(ui.newHeader);
                $('#<%=AccordionIndexHidden.ClientID %>').val(index);
            }
        });
    });


</script>

Remember to start with index less than 0

    <asp:HiddenField ID="AccordionIndexHidden" runat="server" Value="-1" />

FYI, the hidden field is to keep save the accordions open between postbacks

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