Modify Twitter Bootstrap collapse plugin to keep accordions open

前端 未结 4 1598
广开言路
广开言路 2020-12-12 16:19

I\'m trying to modify the Bootstrap collapse plugin to allow me to specify whether clicking an accordion (to open) should automatically close the other items in the accordio

相关标签:
4条回答
  • 2020-12-12 16:34

    I have forked and updated your fiddle.

    just go to .show function, I have written also the comments.

    http://jsfiddle.net/2Rnpz/

    0 讨论(0)
  • 2020-12-12 16:37

    Actually, you don't need to modify any code. Read the following statement closely from twitterbootstrap site

    Just add data-toggle="collapse" and a data-target to element to automatically assign control of a collapsible element. The data-target attribute accepts a css selector to apply the collapse to. Be sure to add the class collapse to the collapsible element. If you'd like it to default open, add the additional class in.

    So instead of using data-parent='#idofAccordion', use data-target='#idofCollapseItem'.

    It should work perfectly.

    Here is the demo on plunker

    0 讨论(0)
  • 2020-12-12 16:43

    since the question didn't refer to a specific version of Bootstrap, here's a bootstrap 4 solution: remove the data-parent="#accordion" from the tags with the data-toggle="collapse" attribute. It's the example taken from the Collapse documentation with the data-parent=#accordion" bit taken out.

    bootply: https://www.bootply.com/3wV4WbzBtT#

    0 讨论(0)
  • 2020-12-12 16:58

    The technique for having only one accordion open at a time(that is collapse the rest), is placing both data-parent="#accordion" data-target="#collapseOne" so it looks like this

    <a class="accordion-toggle" data-toggle="collapse" href="#"
        data-parent="#accordion" data-target="#collapseOne">
      Item #1
    </a>
    

    You can look at it in plunker: http://plnkr.co/edit/56iXtA?p=preview

    0 讨论(0)
提交回复
热议问题