twitter-bootstrap Bootstrap 崩溃
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13110802/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bootstrap collapse
提问by Will Piers
I've spent a few hours trying to get this bootstrap collapse plugin to work. I'm sorry if this question has been asked a bunch before but I've scoured this place for a suitable answer. Here is my html:
我花了几个小时试图让这个 bootstrap 崩溃插件工作。如果之前有人问过这个问题,我很抱歉,但我已经在这个地方搜索了合适的答案。这是我的 html:
<html lang="en">
<head>
<meta charset="utf-8">
<title>:(</title>
<!-- Bootstrap -->
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<h1>Collapse!</h1>
<a class="btn btn-danger" data-toggle="collapse" data-target="#demo">
simple collapsible
</a>
<div id="demo" class="collapse in">
<p>Hopefully this content will be collapsible!</p>
<p>And this too!</p>
</div>
<script type="text/javascript">
$(document).ready(function(){
$(".collapse").collapse()
});
</script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
</body>
</html>
This is also my first use of stackoverflow to ask a question, so excuse the fact that I don't know how to properly format my question. I just added in that little snippet of jquery in the hopes that it would somehow initialize the js elements on the page. Please help!
这也是我第一次使用 stackoverflow 来提问,所以请原谅我不知道如何正确格式化我的问题。我只是添加了一小段 jquery,希望它能以某种方式初始化页面上的 js 元素。请帮忙!
回答by bmscomp
Here is the working version of your code http://jsbin.com/aximay/1/edit
这是您的代码的工作版本http://jsbin.com/aximay/1/edit
回答by blobdon
I see that this question is a bit old, but just an additional note.
我看到这个问题有点旧,但只是一个补充说明。
It seems there is no need to use the Bootstrap data attributes AND the javascript. The BS docs (see Usage)are not clear that these are distinct alternatives, but it works fine with either one independently (data attributes OR JS).
似乎没有必要使用 Bootstrap 数据属性和 javascript。该BS文档(见用法)并不清楚,这些都是不同的选择,但它正常工作与任何一个独立(数据属性或JS)。

