我正在使用基础5.5.3,我正在尝试设置一个简单的手风琴。我像在文档中一样设置了所有内容(http://foundation.zurb.com/sites/docs/v/5.5.3/components/accordion.html)
问题是:当我单击它们时,我可以看到不同的类别使新类"处于活动状态"。它们也会得到 aria-expanded="true"。但是,它不会切换任何内容。此外,当我第二次单击时,该类不会被删除,并且 aria 扩展保持等于"true"。
这是我的网页:
<ul class="accordion" id="myAccordion" data-accordion>
<li class="accordion-navigation"><a href="#cat1">Cat 1</a></li>
<div id="cat1" class="content active">
<ul>
<li><a href="#">Item A</a></li>
<li><a href="#">Item B</a></li>
<li><a href="#">Item C</a></li>
<li><a href="#">Item D</a></li>
</ul>
</div>
<li class="accordion-navigation"><a href="#cat2">Cat 2</a></li>
<div id="cat2" class="content">
<ul>
<li><a href="#">Item 1</a></li>
<li><a href="#">Item 2</a></li>
</ul>
</div>
</ul>
这是我带有控制台输出的 js:
$(document).foundation({
accordion: {
// specify the class used for accordion panels
content_class: 'content',
// specify the class used for active (or open) accordion panels
active_class: 'active',
// allow multiple accordion panels to be active at the same time
multi_expand: true,
// allow accordion panels to be closed by clicking on their headers
// setting to false only closes accordion panels when another is opened
toggleable: true
}
});
$('#myAccordion').on('toggled', function (event, accordion) {
console.log(accordion);
});
这是我的小提琴:https://jsfiddle.net/gfm1ssLa/2/
任何帮助都会得到极大的赞赏...我在论坛上找到的所有内容都没有帮助......
看起来您只是忘记将内容包装在列表中。
<ul class="accordion" id="myAccordion" data-accordion>
<li class="accordion-navigation"><a href="#cat1">Cat 1</a>
<div id="cat1" class="content active">
<ul>
<li><a href="#">Item A</a></li>
<li><a href="#">Item B</a></li>
<li><a href="#">Item C</a></li>
<li><a href="#">Item D</a></li>
</ul>
</div>
</li>
<li class="accordion-navigation"><a href="#cat2">Cat 2</a>
<div id="cat2" class="content">
<ul>
<li><a href="#">Item 1</a></li>
<li><a href="#">Item 2</a></li>
</ul>
</div>
</li>
</ul>
上面的代码应该可以工作。