单击时折叠 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 10:33:49  来源:igfitidea点击:

Collapse jQuery Accordion On Click

jqueryonclickaccordioncollapse

提问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/

回答by suhair

Did you mean the effect as in this demo?

你是说这个演示中的效果吗?

Click the selected tab to toggle its content closed/open. To enable this functionality, set the collapsible optionto true.

单击选定的选项卡以关闭/打开其内容。要启用此功能,请将可折叠设置optiontrue

collapsible: true