手风琴在JQuery Mobile中崩溃/扩展

Gau*_*nan 5 jquery jquery-mobile

我正在使用JQuery Mobile,我的页面上有一堆手风琴.我想一键扩展/折叠所有手风琴,只需点击一下按钮.如何才能做到这一点?

Phi*_*ord 11

这样的事情有用吗?

JS

$('#openAll').on('click', function() {
    $('.openMe').each(function() {
        var coll = $(this);
        coll.trigger('expand');
    });
});
$('#closeAll').on('click', function() {
    $('.openMe').each(function() {
        var coll = $(this);
        coll.trigger('collapse'); 
    });
});
Run Code Online (Sandbox Code Playgroud)

替代JS(没有foreach):

$('#openAll').on('click', function() {
    $('.openMe').trigger('expand');
});
$('#closeAll').on('click', function() {
    $('.openMe').trigger('collapse');
});
Run Code Online (Sandbox Code Playgroud)

HTML

<div data-role="collapsible" class="openMe">
   <h3>Hello 1</h3>
   <p>I'm the collapsible content. By default I'm closed, but you can click the header to open me.</p>
</div>
<div data-role="collapsible" class="openMe">
   <h3>Hello 2</h3>
   <p>I'm the collapsible content. By default I'm closed, but you can click the header to open me.</p>
</div>
<div data-role="collapsible" class="openMe">
   <h3>Hello 3</h3>
   <p>I'm the collapsible content. By default I'm closed, but you can click the header to open me.</p>
</div>
<br />
<a href="#" data-role="button" id="openAll">Open All Collapsible</a>
<a href="#" data-role="button" id="closeAll">Close All Collapsible</a>
?
Run Code Online (Sandbox Code Playgroud)

文档:

看起来这样不会在一个集合上工作,因为一次只能打开一个:

设置文档: