如何使用Jquery点击标签打开所有手风琴?

时间:2014-04-02 09:54:49

标签: jquery css jquery-ui

如何执行此功能

如果我点击<a href="#">Collapse All</a>而不是打开all Accordian再次点击这个Collapse all

我正在使用 uiJqueryAccordian

Fiddle Demo

html代码

<h1>My Accordina</h1>   <a href="#">Collapse All</a>
<div class="js_enrollment">
  <h4>demo section one</h4>
   <div class="">here some text here some text</div>
<h4>demo section one</h4>
   <div class="">here some text here some text</div>
<h4>demo section one</h4>
   <div class="">here some text here some text</div>
<h4>demo section one</h4>
   <div class="">here some text here some text</div>
</div>

jquery代码

    $( ".js_enrollment" ).accordion({ 
    header: "h4",
    icons: { "header": "icon-plus", "headerSelected": "icon-minus" },
    autoHeight: false
});

finding this 但未解决我的问题

1 个答案:

答案 0 :(得分:0)

您可以尝试这样

$('a').on('click', function () {
    if ($('.ui-accordion-content').is(':visible') ){
        $(this).text('Collapse ALl');
    $('.ui-accordion-content').hide();
    }
    else {
        $(this).text('Expand ALl');
        $('.ui-accordion-content').show();
    }
});

JSFiddle