I'm using Bootstrap v2.3.2 with a collapse element.

My accordion looks like this:

<div class="accordion" id="accordion">
        <div class="accordion-heading">
             <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
               <strong><i class="icon-chevron-down"></i>Search options</strong>
             </a>
        </div>
        <div id="collapseOne" class="accordion-body collapse in">
            <div class="accordion-inner">
                Hello
            </div>
        </div>
    </div>
</div>

If i collapse the element #collapseOne by clicking on it, no problem.

But if i call the function$("#collapseOne").collapse('show'); , the element will hide except of showing, but only on first call and only if i don't collapse the element clicking on it before that. I think i forgot a HTML element, but i can't see any difference into DOM...

Fiddle : click on the 'click me' button without clicking on collapsible element before.


Already try: add $accordion.collapse({toggle:true}) (https://github.com/twbs/bootstrap/issues/5859) but it didn't worked...

有帮助吗?

解决方案

$accordion.collapse({toggle:false}) fixes toggle issue, but on wrong element.

You need to fix on #collapseOne

$("#collapseOne").collapse({toggle:false});

FIDDLE

其他提示

I solved this for my solution in my template... Just like that:

$(document).ready(function() {
    $(".panel-body").collapse({ 'toggle': false });
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top