代码之家  ›  专栏  ›  技术社区  ›  Royce

引导程序4.1.3,下拉菜单不工作

  •  0
  • Royce  · 技术社区  · 5 年前

    我用的是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>
    

    enter image description here

    2 回复  |  直到 5 年前
        1
  •  0
  •   zmag    5 年前

    我已经把你的代码写了一小段。看起来工作如期。

    也许你没有包含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>
        2
  •  -2
  •   Royce    5 年前

    用这个 https://getbootstrap.com/docs/4.0/components/dropdowns/

    <div class="dropdown">
      <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
        Dropdown button
      </button>
      <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
        <a class="dropdown-item" href="#">Action</a>
        <a class="dropdown-item" href="#">Another action</a>
        <a class="dropdown-item" href="#">Something else here</a>
      </div>
    </div>