在 jQuery 手风琴中的页面加载时折叠手风琴中的所有部分

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2675263/
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-26 14:01:15  来源:igfitidea点击:

Collapse all sections in accordion on page load in jQuery Accordion

jqueryjquery-ui

提问by Vinay Kumar Chella

I am using JQuery Accordion, I want to hide all the sections on page load. Only when user clicks on header that section should open.

我正在使用 JQuery Accordion,我想在页面加载时隐藏所有部分。仅当用户单击标题时,该部分才应打开。

回答by Daff

Use this in your document ready function when initialising the accordion:

初始化手风琴时,在您的文档准备功能中使用它:

$("#someid").accordion({collapsible : true, active : 'none'});

回答by IBrewThereforeIAm

active : 'none'is an invalid value, it may appear to work on the surface, but will break other aspects of the accordion widget. Use this instead:

active : 'none'是一个无效值,它可能看起来在表面上工作,但会破坏手风琴小部件的其他方面。改用这个:

$("#someid").accordion({collapsible : true, active : false});

回答by Fady Y

This should do it. However it you're looping through a list (in my case its MVC grouped By list) make sure the collapse class is outside of the loop to speed it up substantially.

这应该这样做。但是,您正在遍历一个列表(在我的情况下,它的 MVC 按列表分组)确保折叠类在循环之外以大大加快速度。

$('.collapse').parent().find(".glyphicon-minus").removeClass("glyphicon-minus")
     .addClass("glyphicon-plus").css('color', 'green');

$('.collapse').collapse('hide');

回答by ganji

By url parameters you can expand specific tab or collapse all, for collapsing all use:

通过 url 参数,您可以展开特定选项卡或折叠所有,用于折叠所有使用:

 $("#accordion").accordion('option', 'active' , 'null');

for expanding specific use:

扩大具体用途:

$("#accordion").accordion('option', 'active' , <?php if($_GET['tab']!='')echo $_GET['tab'];else echo 'null'; ?>);