Bootstrap 汉堡菜单无法在 phone 上使用

Bootstrap hamburger menu isn't working on phone

我试图找到问题所在,但对我没有任何帮助。

如果我正在调整浏览器的大小,汉堡包菜单会弹出并起作用,但是当我查看 phone 时它不起作用。 我真的做错了吗?

我使用的代码:

HTML:

    <nav class="navbar navbar-inverse navbar-fixed-top">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">Roy van Eerden</a>
    </div>
    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav navbar-right">
        <li class="active"><a href="#about">Home</a></li>
        <li><a href="#skills">Portfolio</a></li>
        <li><a href="#experience">Over</a></li>
        <li><a href="#contact">Contact</a></li>
      </ul>
    </div>
  </div>
</nav>

您可以在以下位置实时观看:www.royvaneerden.com/

phone 示例的屏幕截图:

只需将 jquery.js 放在 bootstrap.min.js 上方

另外,在 head 中添加 meta

<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;" />

点这里

只需在标题中添加此元标记

<meta name="viewport" content="width=device-width, initial-scale=1.0">

您缺少整个 html 部分,请用此处的导航(w3school 文档)替换您拥有的部分。

<nav class="navbar navbar-inverse">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">WebSiteName</a>
    </div>
    <div class="collapse navbar-collapse" id="myNavbar">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Home</a></li>
        <li class="dropdown">
          <a class="dropdown-toggle" data-toggle="dropdown" href="#">Page 1 <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#">Page 1-1</a></li>
            <li><a href="#">Page 1-2</a></li>
            <li><a href="#">Page 1-3</a></li>
          </ul>
        </li>
        <li><a href="#">Page 2</a></li>
        <li><a href="#">Page 3</a></li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
        <li><a href="#"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
      </ul>
    </div>
  </div>
</nav>

或通过检查 link Collapse Menu Bootstrap