Bootstrap 4折叠按钮不可点击

时间:2018-10-16 10:14:37

标签: html css twitter-bootstrap

我正在一个网站上。我本来打算有一个折叠菜单,但是折叠按钮似乎不起作用。

 <link rel="stylesheet" type="text/css" href="css/style.css"/>
 <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
 <link rel="stylesheet" type="text/css" href="css/bootstrap-grid.css"/>
 <link rel="stylesheet" type="text/css" href="css/bootstrap-reboot.css"/>

</head>

<body>

<div class="pos-f-t">
<div class="collapse" id="navbarToggleExternalContent">
<div class="bg-dark p-4">
  <h4 class="text-white">Title here.</h4>
  <span class="text-muted">Text here.</span>
</div>
</div>
<nav class="navbar navbar-dark bg-dark">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarToggleExternalContent" aria-controls="navbarToggleExternalContent" aria-expanded="false" aria-label="Toggle navigation">
  <span class="navbar-toggler-icon"></span>
 </button>
 </nav>
 </div>



 <!-- SCRIPT -->
 <script  src="js/bootstrap.js"></script>
 <script  src="js/bootstrap.bundle.js"></script>
 <script  src="js/jquery-1.11.2.min.js"></script>
 <!-- END OF SCRIPT -->
 </body>


 </html>

我从引导站点本身复制了此代码,然后将其粘贴到我的Dreamweaver上并加载了它,栏和折叠按钮都在那儿。

4 个答案:

答案 0 :(得分:0)

尝试使用live link中的css and script或下载库,然后使其工作脱机。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!--<link rel="stylesheet" type="text/css" href="css/style.css"/>
 <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
 <link rel="stylesheet" type="text/css" href="css/bootstrap-grid.css"/>
 <link rel="stylesheet" type="text/css" href="css/bootstrap-reboot.css"/>-->



<body>

  <div class="pos-f-t">
    <div class="collapse" id="navbarToggleExternalContent">
      <div class="bg-dark p-4">
        <h4 class="text-white">Title here.</h4>
        <span class="text-muted">Text here.</span>
      </div>
    </div>
    <nav class="navbar navbar-dark bg-dark">
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarToggleExternalContent" aria-controls="navbarToggleExternalContent" aria-expanded="false" aria-label="Toggle navigation">
  <span class="navbar-toggler-icon"></span>
 </button>
    </nav>
  </div>



  <!-- SCRIPT -->
  <script src="js/bootstrap.js"></script>
  <script src="js/bootstrap.bundle.js"></script>
  <script src="js/jquery-1.11.2.min.js"></script>
  <!-- END OF SCRIPT -->
</body>


</html>

答案 1 :(得分:0)

看上去您的javascript文件的顺序不正确。

您也不需要bootstrap.js和bootstrap.bundle.js,只需使用捆绑包即可,因为它是1个组合文件中的bootstrap.js + popper.js(请参阅:https://getbootstrap.com/docs/4.1/getting-started/contents/#js-files)。

所以...尝试将您的JavaScript更改为:

<!-- SCRIPT -->
<script  src="js/jquery-1.11.2.min.js"></script>
<script  src="js/bootstrap.bundle.js"></script>
<!-- END OF SCRIPT -->

编辑:看来您的css文件顺序也不正确,而且您不需要全部。.将它们更改为:

<link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
<link rel="stylesheet" type="text/css" href="css/style.css"/>

答案 2 :(得分:0)

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.bundle.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
 <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
 <link rel="stylesheet" type="text/css" href="css/bootstrap-grid.css"/>
 <link rel="stylesheet" type="text/css" href="css/bootstrap-reboot.css"/>

</head>

<body>

<div class="pos-f-t">
<div class="collapse" id="navbarToggleExternalContent">
<div class="bg-dark p-4">
  <h4 class="text-white">Title here.</h4>
  <span class="text-muted">Text here.</span>
</div>
</div>
<nav class="navbar navbar-dark bg-dark">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarToggleExternalContent" aria-controls="navbarToggleExternalContent" aria-expanded="false" aria-label="Toggle navigation">
  <span class="navbar-toggler-icon"></span>
 </button>
 </nav>
 </div>



 <!-- SCRIPT -->
 <script  src="js/bootstrap.js"></script>
 <script  src="js/bootstrap.bundle.js"></script>
 <script  src="js/jquery-1.11.2.min.js"></script>
 <!-- END OF SCRIPT -->
 </body>


 </html>

您可能会丢失项目文件夹中的某些CSS或JS文件。

答案 3 :(得分:0)

问题肯定与您的引导程序依赖文件有关。使用CDN用于js和css,页面可以轻松工作,或者脱机工作,您应该下载引导程序文件,并应以正确的顺序放置以正确的顺序导入 Refer
您可以尝试此操作(使用Bootstrap CDN):

<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<link rel="stylesheet" type="text/css" href="css/style.css"/>
 <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
 <link rel="stylesheet" type="text/css" href="css/bootstrap-grid.css"/>
 <link rel="stylesheet" type="text/css" href="css/bootstrap-reboot.css"/>  -->

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<body>

  <div class="pos-f-t">
    <div class="collapse" id="navbarToggleExternalContent">
      <div class="bg-dark p-4">
        <h4 class="text-white">Title here.</h4>
        <span class="text-muted">Text here.</span>
      </div>
    </div>
    <nav class="navbar navbar-dark bg-dark">
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarToggleExternalContent" aria-controls="navbarToggleExternalContent" aria-expanded="false" aria-label="Toggle navigation">
  <span class="navbar-toggler-icon"></span>
 </button>
    </nav>
  </div>



<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>


</html>