下拉汉堡包不工作Jquery和JS CDN放置是正确的

时间:2017-10-18 11:53:10

标签: javascript jquery html5

当屏幕格式化为iphone大小时,我只是想让汉堡包图标下拉到导航栏,但它不会下拉。

我也很确定JS和jquery的位置是正确的。

<head>
    <title>Bootstrap Example</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

    <link rel="stylesheet" type="text/css" href="Portfolio.css">

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

    </head>
    <body>   
        <!-- NAVBAR -->
            <nav id="myNavbar" class="navbar navbar-default navbar-fixed-top" role="navigation">
                <div class="container-fluid">
                    <div class="navbar-header">
                        <button type="button" class="navbar-toggle" data-toggle="collpase" data-target=".navbar-collapse">
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </button>

                        <a href="#" class="navbar-brand">COTO</a>
                    </div>
                    <div class="navbar-collapse collapse">
                        <ul class="nav navbar-nav navbar-right">
                            <li><a href="#header">Home</a></li>

                            <li><a href="#Services">Services</a></li>

                            <li><a href="#pricing">Pricing</a></li>

                            <li><a href="#Team">Team</a></li>

                            <li><a href="#Clients">Clients</a></li>

                            <li><a href="#Contact">Contact</a></li>
                        </ul>
                    </div>
                </div>
            </nav>
         <!-- NAVBAR END -->    
    </body>
    </html>

2 个答案:

答案 0 :(得分:0)

根据Bootstrap(https://getbootstrap.com/docs/4.0/components/navbar/):

  1. 您的数据切换属性不正确:
  2. data-toggle="collpase"data-toggle="collapse"

    1. 将导航栏切换按钮的data-target属性更改为ID选择器而不是类选择器:
    2. data-target=".navbar-collapse"data-target="#navbar"

      1. 将ID属性添加到导航栏:
      2. <div class="navbar-collapse collapse" id="navbar">

答案 1 :(得分:0)

data-toggle属性只有一点错字。此外,在尝试选择单个元素时,必须始终使用ID选择器。这是一个工作示例(已测试):

<head>
    <title>Bootstrap Example</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

    <link rel="stylesheet" type="text/css" href="Portfolio.css">

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

    </head>
    <body>   
        <!-- NAVBAR -->
            <nav id="myNavbar" class="navbar navbar-default navbar-fixed-top" role="navigation">
                <div class="container-fluid">
                    <div class="navbar-header">
                        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNav">
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </button>

                        <a href="#" class="navbar-brand">COTO</a>
                    </div>
                    <div class="navbar-collapse collapse" id="myNav">
                        <ul class="nav navbar-nav navbar-right">
                            <li><a href="#header">Home</a></li>

                            <li><a href="#Services">Services</a></li>

                            <li><a href="#pricing">Pricing</a></li>

                            <li><a href="#Team">Team</a></li>

                            <li><a href="#Clients">Clients</a></li>

                            <li><a href="#Contact">Contact</a></li>
                        </ul>
                    </div>
                </div>
            </nav>
         <!-- NAVBAR END -->    
    </body>
    </html>