jQuery - 手风琴(De-Collapse)

时间:2012-09-27 13:03:48

标签: jquery html jquery-ui accordion jquery-ui-accordion

嗯,这个问题是我的earlier question的下一个版本。

由于我已将所有链接折叠,我想创建一个按钮或链接说“全部显示”,点击它会使所有链接都按手风琴激活,即我想查看所有链接的数据。还需要创建一个按钮或链接,说“全部隐藏”,这将使折叠状态变得更早。

倒塌的状态

+++++++++++++++++++++++++++++++++++++++
+   Link 1                            +
+   Link 2                            +
+   Link 3                            +
+   Link 4                            +
+++++++++++++++++++++++++++++++++++++++

点击“全部显示”后应该获得

+++++++++++++++++++++++++++++++++++++++
+   Link 1                            +
+     Link 1 line 1                   +
+     Link 1 line 2                   +
+     Link 1 line 3                   +
+   Link 2                            +
+     Link 2 line 1                   +
+     Link 2 line 2                   +
+     Link 2 line 3                   +
+   Link 3                            +
+     Link 3 line 1                   +
+     Link 3 line 2                   +
+   Link 4                            +
+     Link 4 line 1                   +
+     Link 4 line 2                   +
+++++++++++++++++++++++++++++++++++++++

怎么做?

2 个答案:

答案 0 :(得分:0)

作为 hack 最后的手段),您可以使用

// highlight headers
$("#accordion001").find('h3.ui-accordion-header')
                  .removeClass('ui-state-default')
                  .addClass('ui-state-active');

//open content panels
$("#accordion001").find('div.ui-accordion-content')
                  .addClass('ui-accordion-content-active')
                  .show();

但是你也需要处理结束(撤消我们做的事情),因为当前的代码混淆了默认行为..

答案 1 :(得分:0)

以下是扩展和折叠所有内容面板的解决方案。

function expandAll() {
    $('#accordion h3').removeClass('ui-state-default')
        .addClass('ui-state-active')
        .removeClass('ui-corner-all')
        .addClass('ui-corner-top')
        .attr('aria-expanded', 'true')
        .attr('aria-selected', 'true')
        .attr('tabIndex', 0)
    .find('span.ui-icon')
        .removeClass('ui-icon-triangle-1-e')
        .addClass('ui-icon-triangle-1-s')
    .closest('h3').next('div')
        .show();

    $('.expand').text('collapse all').unbind('click').bind('click', collapseAll);

    $('#accordion h3').bind('click.collapse', function() {
        collapseAll();
        $(this).click();
    });
}

function collapseAll() {
    $('#accordion h3').unbind('click.collapse');

    $('#accordion h3').removeClass('ui-state-active')
            .addClass('ui-state-default')
            .removeClass('ui-corner-top')
            .addClass('ui-corner-all')
            .attr('aria-expanded', 'false')
            .attr('aria-selected', 'false')
            .attr('tabIndex', -1)
        .find('span.ui-icon')
            .removeClass('ui-icon-triangle-1-s')
            .addClass('ui-icon-triangle-1-e')
        .closest('h3').next('div')
            .hide();

    $('.expand').text('expand all').unbind('click').bind('click', expandAll);

    $('#accordion').accordion('destroy').accordion();
}

和小提琴

http://jsfiddle.net/wa9Dz/1/