单击时折叠 jQuery 手风琴
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9260068/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Collapse jQuery Accordion On Click
提问by GStubbenhagen
I have created an accordion using jQuery which collapses fine when the user clicks a 2nd option but I would also like to have the option to collapse the open pane by clicking again on the header, how should I do this?
我已经使用 jQuery 创建了一个手风琴,当用户单击第二个选项时它会很好地折叠,但我也希望可以选择通过再次单击标题来折叠打开的窗格,我该怎么做?
Here's a fiddle showing how I've set it up so far: http://jsfiddle.net/gstubbenhagen/JyFRC/
这是一个小提琴,展示了到目前为止我是如何设置的:http: //jsfiddle.net/gstubbenhagen/JyFRC/
EDIT: Replaced code examples w/ jsFiddle link
编辑:用 jsFiddle 链接替换代码示例
回答by user993563
//Initialize a accordion with the collapsible option specified.
$( ".selector" ).accordion({ collapsible: true });
//Get or set the collapsible option, after init.
//getter
var collapsible = $( ".selector" ).accordion( "option", "collapsible" );
//setter
$( ".selector" ).accordion( "option", "collapsible", true );
Source: http://jqueryui.com/demos/accordion/#option-collapsible
来源:http: //jqueryui.com/demos/accordion/#option-collapsible
find this demo: http://jsfiddle.net/2DaR6/
找到这个演示:http: //jsfiddle.net/2DaR6/