简体   繁体   English

Bootstrap手风琴元素不会关闭

[英]Bootstrap accordion elements won't close

I am trying to make an accordion menu in Bootstrap. 我正在尝试在Bootstrap中制作一个手风琴菜单。 Here's a minimal example of what I'm trying to do: http://jsfiddle.net/ra2crej1/ 这是我要执行的操作的最小示例: http : //jsfiddle.net/ra2crej1/

While the elements do open, for some reason they do not close on click. 元素确实打开时,由于某种原因,它们不会在单击时关闭。 How do I fix this? 我该如何解决?

I'm using the code from the documentation here , but for some reason in JSFiddle it does not behave as it does in the docs. 我使用的代码的文件在这里 ,但由于某种原因在它的jsfiddle不表现为它在文档中一样。

Here is the HTML code: 这是HTML代码:

<div class="panel-group" id="accordion">
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
          Collapsible Group Item #1
        </a>
      </h4>
    </div>
    <div id="collapseOne" class="panel-collapse collapse">
      <div class="panel-body">
        Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
      </div>
    </div>
  </div>
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo">
          Collapsible Group Item #2
        </a>
      </h4>
    </div>
    <div id="collapseTwo" class="panel-collapse collapse">
      <div class="panel-body">
        Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
      </div>
    </div>
  </div>
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a data-toggle="collapse" data-parent="#accordion" href="#collapseThree">
          Collapsible Group Item #3
        </a>
      </h4>
    </div>
    <div id="collapseThree" class="panel-collapse collapse">
      <div class="panel-body">
        Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
      </div>
    </div>
  </div>
</div>

Thanks in advance for the help! 先谢谢您的帮助!

It seems to me that you don't have the bootstrap.js file being loaded in anywhere. 在我看来,您没有在任何地方加载bootstrap.js文件。 You want to have the bootstrap.js file being loaded and in the header of your document go ahead and add this code: 您要加载bootstrap.js文件,并在文档标题中继续添加以下代码:

<script type="text/javascript">
$(document).ready(function () {
$('.collapse').collapse
});

</script>

here's a working jsfiddle: http://jsfiddle.net/ra2crej1/2/ 这是一个工作的jsfiddle: http : //jsfiddle.net/ra2crej1/2/

and here's a working jsfiddle with your content: http://jsfiddle.net/ra2crej1/3/ 这是一个工作正常的jsfiddle,其中包含您的内容: http : //jsfiddle.net/ra2crej1/3/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM