使用以下代码使第一个Accordion容器打开所需的JS是什么:
答案 0 :(得分:0)
$('#vertical-container h1:first').click();
假设您使用的是jQuery。
或
$('#vertical-container h1:first').addClass('accordion_toggle_active');
可能有用。
答案 1 :(得分:0)
您当前的代码:
function loadAccordions() {
var bottomAccordion = new accordion('vertical_container');
var nestedVerticalAccordion = new accordion('vertical_nested_container', {
classNames : {
toggle : 'vertical_accordion_toggle',
toggleActive : 'vertical_accordion_toggle_active',
content : 'vertical_accordion_content'
}
});
// Open first one
bottomAccordion.activate($$('#vertical_container .accordion_toggle')[0]);
}
问题是VerticalNestedContainer不存在。所以bottomAccordion.activate从未被执行过。您可以删除未使用过的手风琴或在此之前检查它是否存在:
function loadAccordions() {
var bottomAccordion = new accordion('vertical_container');
if($('vertical_nested_container')){
var nestedVerticalAccordion = new accordion('vertical_nested_container', {
classNames : {
toggle : 'vertical_accordion_toggle',
toggleActive : 'vertical_accordion_toggle_active',
content : 'vertical_accordion_content'
}
});
}
// Open first one
bottomAccordion.activate($$('#vertical_container .accordion_toggle')[0]);
}
或只是:
function loadAccordions() {
var bottomAccordion = new accordion('vertical_container');
// Open first one
bottomAccordion.activate($$('#vertical_container .accordion_toggle')[0]);
}