最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Call of bootstrap collapse('show') hide element only the first time - Stack Overflow

programmeradmin0浏览0评论

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}) () but it didn't worked...

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./twbs/bootstrap/issues/5859) but it didn't worked...

Share Improve this question asked Feb 27, 2014 at 10:49 GetzGetz 4,0636 gold badges37 silver badges52 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

$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 });
});
发布评论

评论列表(0)

  1. 暂无评论