【问题标题】:Bootstrap 4.1.3, dropdown menu not workingBootstrap 4.1.3,下拉菜单不起作用
【发布时间】:2019-03-09 20:37:04
【问题描述】:

我正在使用 Bootstrap 4.1.3,并尝试使用下拉菜单进行导航。我按照这个例子:https://getbootstrap.com/docs/4.1/components/navs/#using-dropdowns

但是,它不起作用。

你能帮帮我吗?

非常感谢。

我的代码

<div>
     <ul class="nav justify-content-center">
          <li class="nav-item dropdown">
                 <a class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Oeuvres</a>
                 <div class="dropdown-menu">
                     <a class="dropdown-item" href="/" th:href="@{/oeuvres/}">Toutes les oeuvres</a>
                     <div class="dropdown-divider"></div>
                     <a class="dropdown-item" href="/" th:href="@{/oeuvres/livres/}">Livres</a>
                     <a class="dropdown-item" href="/" th:href="@{/oeuvres/magasines/}">Magasines</a>
                 </div>
            </li>
       </ul>
  </div>

编辑 1:JS 文件 (https://getbootstrap.com/docs/4.1/getting-started/introduction/#js)

<head xmlns:th="http://www.thymeleaf.org" th:fragment="header">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <link rel="stylesheet" th:href="@{/css/main.css}">
    <link rel="stylesheet" th:href="@{/css/bootstrap.min.css}">
    <script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
    <script type="text/javascript" th:src="@{/js/popper.min.js}"></script>
    <script type="text/javascript" th:src="@{/js/bootstrap.min.js}"></script>
    <script type="text/javascript" th:src="@{/js/main.js}"></script>
    <title>Bibliothèque</title>
</head>

【问题讨论】:

  • 您的&lt;ul&gt; 没有课程。
  • @HamzStramGram 这是一个错误,我编辑了我的问题。谢谢。
  • 你在加载所需的CSS & JS
  • 您已经添加了引导 CSS 和所需的 JS 文件?正如文档的“入门”部分所说的那样?
  • 我用使用的 JS 文件更新了我的问题。

标签: html css bootstrap-4


【解决方案1】:

我已经对你的代码做了一个 sn-p。它似乎按预期工作。

也许你没有包含 JavaScript 文件。

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


<div>
  <ul class="nav justify-content-center">
    <li class="nav-item dropdown">
      <a class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Oeuvres</a>
      <div class="dropdown-menu">
        <a class="dropdown-item" href="/" th:href="@{/oeuvres/}">Toutes les oeuvres</a>
        <div class="dropdown-divider"></div>
        <a class="dropdown-item" href="/" th:href="@{/oeuvres/livres/}">Livres</a>
        <a class="dropdown-item" href="/" th:href="@{/oeuvres/magasines/}">Magasines</a>
      </div>
    </li>
  </ul>
</div>

【讨论】:

  • 这很奇怪......我用(在本地)使用的 js 文件更新了我的问题。
  • 无法重现问题是您应该在评论中提及的内容,而不是答案。
  • @zmag 此外,您使用的是引导程序 4.0.0。我使用 4.1.3。我不知道这是否重要。
猜你喜欢
  • 2019-04-08
  • 2019-05-28
  • 2013-01-21
  • 2012-03-20
  • 2021-12-19
  • 2020-07-13
  • 2018-02-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多