Bootstrap导航栏折叠按钮不起作用

时间:2019-03-02 20:53:45

标签: javascript html css

我正在尝试折叠此导航栏,但无法正常工作。希望您能够帮助我。该按钮没有执行任何操作。

这是我的代码:

<nav class="navbar navbar-expand-md navbar-dark bg-dark mb-4">
  <a class="navbar-brand" href="/lsapp/public/">{{config ('app.name', 'LSAPP')}}</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="#navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarCollapse">
      <ul class="navbar-nav mr-auto">
        <li class="nav-item ">
          <a class="nav-link" href="/lsapp/public/">Home <span class="sr-only">(current)</span></a>
        </li>
        <li class="nav-item ">
          <a class="nav-link" href="/lsapp/public/about">About</a>
        </li>
        <li class="nav-item">
          <a class="nav-link " href="/lsapp/public/services" tabindex="-1">Services</a>
        </li>
        <li class="nav-item">
            <a class="nav-link " href="/lsapp/public/posts" tabindex="-1">Blog</a>
          </li>
      </ul>
     <form class="form-inline mt-2 mt-md-0">
        <input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
        <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
      </form>
    </div>
  </nav>

2 个答案:

答案 0 :(得分:0)

我已经测试了您的代码及其工作。我猜你在加载bootstrap.js之前遇到了一个JavaScript错误。

或者在引导程序之前未加载jQuery。

请检查浏览器控制台(F12)

答案 1 :(得分:0)

它正在工作,请检查您是否正确链接了Bootstrap CSS和JS文件 如果您使用的是CDN,那么

<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
//Your navbar code here
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>

如果您不使用CDN,则应将src替换为文件路径