我似乎无法使用jQuery Accordions具有多个描述项 (dd) 的定义列表。作者examples只有单个 dd 项目。
在下面的示例中,B2、B3 和 C2 显示 onLoad,而不是像我希望的那样像 A1、B1 和 C1 那样隐藏。
我如何实现这一目标?
jQuery('dl').accordion({
event: 'click',
active: false,
animated: "bounceslide",
header: "dt"
});
<dl>
<dt>A</dt>
<dd>A1</dd>
<dt>B</dt>
<dd>B1</dd>
<dd>B2</dd>
<dd>B3</dd>
<dt>C</dt>
<dd>C1</dd>
<dd>C2</dd>
</dl>
最佳答案
$(function () {
$('dt').on('click', function (e) {
e.preventDefault();
$(this).parent('dl').children('dd:visible').slideUp('slow');
$(this).nextUntil('dt').filter(':not(:visible)').slideDown('slow');
});
});
注意:
如果您想要多个部分
open at once, don't use an accordion
- An accordion doesn't allow more than one content panel to be open at the same time, and it takes a lot of effort to do that. If you are looking for a widget that allows more than one content panel to be open, don't use this. Usually it can be written with a few lines of jQuery instead, something like this: REFERENCE: http://jqueryui.com/demos/accordion/
希望这有帮助! ;)
关于具有多个描述项的 jQuery Accordion 定义列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3404657/