开发者

jQuery Accordion Closed at Load

开发者 https://www.devze.com 2023-02-11 15:31 出处:网络
How can I get the accordion widget to be closed when the page loads? This is the code I\'m using: //Accordion

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

//Accordion
    $( ".accordi开发者_JAVA百科on" ).accordion({
        autoHeight: false,
        navigation: true,
        collapsible: true,
        active: false
    });

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


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.


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

0

精彩评论

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