具有多个描述项的 jQuery Accordion 定义列表

标签 jquery jquery-ui unobtrusive-javascript

我似乎无法使用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>

( Live jsFiddle version )

最佳答案

$(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/

相关文章:

jquery - Google map (API v2)+ jQuery UI 对话框,不可停止的拖动问题

jquery - 不引人注目但可用的跨度按钮?

jquery - 关于 MS jquery.validate.unobtrusive.js 文件的问题

jquery-animate - 可以使 jquery.live() 与负载一起工作吗?

javascript - Jquery:在检查最后一个字母时将文本从表单复制到 DIV

javascript - 在 jQuery 中实现 CSS

jquery - 使用 jQuery 和 Masonry 无限滚动获取动态内容

c# - JQuery 模态对话框使用追加显示在叠加层后面

jquery-ui - JQuery UI 对话框问题 : Close removes the div

javascript - 总结一个javascript字符串数组