我是 Twitter Bootstrap 的新手,在尝试实现手风琴时遇到一些问题,如官方文档示例所示:http://getbootstrap.com/javascript/#collapse-example-accordion
我刚刚将之前的 HTML 代码复制并粘贴到我的页面中,我看到了手风琴内容,但我发现第一个面板已展开,其他 2 个面板已折叠。问题是我无法在这些面板上进行交互。如果我单击第一个面板,它不会折叠,如果我单击 2-3 个面板,它不会展开。
所以,这是我的页面内容:
<!DOCTYPE html>
<html>
<head>
<link href="<c:url value="resources/css/style.css" />" rel="stylesheet">
<link href="<c:url value="resources/css/bootstrap.css" />" rel="stylesheet">
<link href="<c:url value="resources/css/bootstrap-theme.css" />" rel="stylesheet">
<script src="<c:url value="resources/js/bootstrap.js" />"></script>
<title>Home</title>
</head>
<body>
<section>
<div class="container alignLeft">
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Collapsible Group Item #1
</a>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
<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" role="tab" id="headingTwo">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
Collapsible Group Item #2
</a>
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
<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" role="tab" id="headingThree">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
Collapsible Group Item #3
</a>
</h4>
</div>
<div id="collapseThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingThree">
<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>
</div>
</section>
</body>
</html>
如您所见,我已正确包含 bootstrap.css 文件和 bootstrap.js 文件。
我错过了什么?我怎样才能解决这个问题并获得一个可用的手风琴?
需要在代码中包含实际的 jQuery 库。
将其放入您的
head
:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
首先你必须包含脚本 jQuery(功能丰富的 JavaScript 库)位于 bootstrap 脚本之前,用于使任何内容都能与 bootstrap 配合使用。
以下是如何通过在 bootstrap 脚本之前包含最新版本的 jQuery 来使其工作。
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="<c:url value="resources/js/bootstrap.js" />"></script>
您可能还想检查是否要使整个面板可单击,或者只是标题中的标题部分(当前情况)。