Bootstrap导航栏无法打开,链接也不会显示

时间:2018-01-25 23:47:43

标签: html bootstrap-4

我正在尝试使用带有链接的导航栏和用于小屏幕的可折叠菜单。但是,我有两个问题:

  1. 在正常尺寸的屏幕上,链接不会显示
  2. 在移动设备上,点击菜单打开按钮时,菜单会打开,但会立即崩溃。
  3. 以下是jsfiddle上我的代码的链接。感谢

    
    
    <!DOCTYPE html>
    
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <meta viewport="viewport" content="width=device-width, initial-scale=1.0 ">
      <meta http-equiv="X-UA-Compatible" content="ie=edge">
      <title>Page name</title>
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
      <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.no-icons.min.css" rel="stylesheet">
      <link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">
      <link rel="stylesheet" href="css/style.css">
    </head>
    <body>
    
    
    
    <nav class="navbar navbar-default navbar-expand-md bg-dark navbar-dark">
      <a class="navbar-brand" href="#">Page Name</a>
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#thetarget">
        <span class="navbar-toggler-icon"></span>
      </button>
      <div class="collapse navbar-collapse" id="thetarget">
        <ul class="navbar-nav">
          <li class="nav-item">
            <a class="nav-link" href="page1.html">txt</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#" target="_blank">txt1</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#" target="_blank">txt2</a>
          </li>
        </ul>
      </div>
    </nav>
    
    
    
        <!-- Bootstrap core JavaScript -->
    
        <!-- Menu Toggle Script -->
        <script>
        $("#menu-toggle").click(function(e) {
            e.preventDefault();
            $("#wrapper").toggleClass("toggled");
        });
        </script>
    
    
    
      <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>
    &#13;
    &#13;
    &#13;

1 个答案:

答案 0 :(得分:1)

我使用w3school页面重新创建了navbar bootstrap here。我更改了head标签中的脚本标签并编写了一些代码。希望这会有所帮助。

 <nav class="navbar navbar-inverse">
  <div class="container-fluid">
   <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#thetarget">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>                        
      </button>
      <a class="navbar-brand" href="#">Page Name</a>
    </div>
  <div class="collapse navbar-collapse" id="thetarget">
    <ul class="nav navbar-nav">
      <li> <a class="nav-link" href="page1.html">txt</a> </li>
      <li><a class="nav-link" href="#" target="_blank">txt1</a></li>
      <li><a class="nav-link" href="#" target="_blank">txt2</a></li>
    </ul>
  </div>
 </div>
</nav>