简体   繁体   English

如何实现twitter bootstrap手风琴?

[英]How to implement twitter bootstrap accordion?

I'm trying to implement the twitter bootstrap collapse plugin ( http://twitter.github.io/bootstrap/2.3.2/javascript.html#collapse ) and I can't seem to get it working. 我正在尝试实现twitter bootstrap collapse插件( http://twitter.github.io/bootstrap/2.3.2/javascript.html#collapse ),我似乎无法让它工作。 Thinking it was something wrong with my development environment, I set up a JSfiddle and I'm still getting the same issues. 认为我的开发环境有问题,我设置了一个JSfiddle,我仍然遇到同样的问题。 Here's the jsfiddle: 这是jsfiddle:

http://jsfiddle.net/qdqrT/1/ http://jsfiddle.net/qdqrT/1/

Here is the HTML which was copied directly from the bootstrap example. 这是直接从bootstrap示例复制的HTML。

<div class="accordion" id="accordion2">
  <div class="accordion-group">
    <div class="accordion-heading">
      <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne">
        Collapsible Group Item #1
      </a>
    </div>
    <div id="collapseOne" class="accordion-body collapse in">
      <div class="accordion-inner">
        Anim pariatur cliche...
      </div>
    </div>
  </div>
  <div class="accordion-group">
    <div class="accordion-heading">
      <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseTwo">
        Collapsible Group Item #2
      </a>
    </div>
    <div id="collapseTwo" class="accordion-body collapse">
      <div class="accordion-inner">
        Anim pariatur cliche...
      </div>
    </div>
  </div>
</div>

The CSS and javscript were taken directly from the bootstrap customize page, with only the collapse CSS and JS, and the trasition JS (which is a dependency for the collapse plugin). CSS和javscript直接来自bootstrap自定义页面,只有崩溃的CSS和JS,以及trasition JS(它是崩溃插件的依赖项)。

Anyone know why this is broken? 有谁知道为什么这个坏了?

I got it working. 我搞定了。 I think you might not be including all the required resources. 我想你可能没有包括所有必需的资源。

I ended up including a hosted version of bootstrap CSS and JS from BootstrapCDN 我最终在BootstrapCDN中包含了一个托管版本的bootstrap CSS和JS

<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.no-icons.min.css" rel="stylesheet">

Here is the working version: http://jsfiddle.net/qdqrT/3/ 这是工作版本: http//jsfiddle.net/qdqrT/3/

I tried it with a newer version of bootstrap (3.3.4) and the code in the question worked when the correct files are included. 我尝试使用较新版本的bootstrap(3.3.4),当包含正确的文件时,问题中的代码也能正常工作。

It wasn't necessary to use the CDN version of bootstrap (but you can if you wish). 没有必要使用CDN版本的bootstrap(但如果你愿意,你可以使用)。

I have bootstrap in a subdirectory and the following in my HTML: 我在一个子目录中有bootstrap,我的HTML中有以下内容:

<!-- Bootstrap CSS (put this in the header of your HTML file)-->
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css">

<!-- Bootstrap Javascript (put this at the end of your HTML file)-->
<script src="bootstrap/js/bootstrap.min.js"></script>

(I realise that the question is old, but I think my answer is more up to date than the accepted answer and hopefully it will help someone) (我意识到这个问题已经过时了,但我认为我的答案比接受的答案更新,希望它能帮到某些人)

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

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