问题
I will like to organize the structure and the design of my web system, for this reason I decided for the accordion component of jQuery (which is working pretty good) because I don't want to disturb the user with unnecessary space, so the user can decide if he want to see or not this information.
My problem is that I just have one section inside this accordion (this section is a panel of components) and I can not collapse one section in the accordion (at least I don't know how). If I add another section then is possible, but I just need one.
Can somebody help me in this case?
回答1:
You should set collapsible to true to indicate that all the sections can be closed at once. Unless you specify this, when you only have one section you can't close it since one section should be active all the time by default.
Set active to false if you want the section to be collapsed initially
$("#accordion").accordion({
active: false,
collapsible: true
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<div id="accordion">
<h3>Section 1</h3>
<div>
<p>Mauris mauris ante, blandit et, ultrices a, suscipit eget. Integer ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut odio.</p>
</div>
</div>
来源:https://stackoverflow.com/questions/34629246/is-it-possible-to-have-only-one-section-in-jquery-ui-accordion