jquery ui accordion - render closed
I have a jquery.ui accordion working. I wish that all the divs are closed on creation.开发者_Python百科 I always get the first item opened and i can't seem to find in the documentation a way to do it. Is that possible?
Thanks
You want a combination of the active
and collapsible
options:
$( "#accordion" ).accordion({
collapsible: true,
active: false
});
Here's an example: http://jsfiddle.net/andrewwhitaker/gjMfZ/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" />
精彩评论