单击时,Bootstrap下拉按钮未打开

时间:2018-02-06 05:08:53

标签: html css twitter-bootstrap web bootstrap-4

我正在尝试使用引导程序构建一个带按钮的导航栏,但下拉菜单不会在点击时打开。我在正确的位置的代码中包含了bootstrap CDN链接,bootstrap css链接,ajax popper链接和jquery链接。我没有在导航栏按钮中添加任何外部CSS。这可能是什么问题?

这是一个片段:

| sed 's/^\.//'

main.js文件包含:

 <!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Page Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <script defer src="https://use.fontawesome.com/releases/v5.0.6/js/all.js"></script>

    <script src="main.js"></script>
</head>

<body>
    <nav class="navbar navbar-expand-lg navbar fixed-top navbar-light bg-light">
        <span class="navbar-toggler-icon"></span>
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <ul class="navbar-nav mr-auto ">
                <li class="nav-item">
                    <div class="new-pickup"> <a class="nav-link" id="new-pickup" href="#"><i class="fa fa-plus"id="add-plus" aria-hidden="true"></i>
                     New Pickup&nbsp;&nbsp;&nbsp;&nbsp;</a></div>
                    <li class="nav-item dropdown">
                        <div class="sms-button">
                            <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                          &nbsp;SMS&nbsp;&nbsp;
                        </a>
                        </div>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                            <a class="dropdown-item" href="#">Delivered Status</a>
                            <a class="dropdown-item" href="#">Log details</a>
                        </div>
                    </li>
                    <li class="nav-item dropdown">
                        <div class="email-button">
                            <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                            &nbsp;Email&nbsp;&nbsp;
                          </a>
                        </div>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                            <a class="dropdown-item" href="#">Deivered Status</a>
                            <a class="dropdown-item" href="#">Log Status</a>
                        </div>
                    </li>
                    <li class="nav-item">
                        <div class="call-button">
                            <a class="nav-link" href="#"><i class="fa fa-phone fa-flip-horizontal " aria-hidden="true"></i>
                          Call&nbsp;&nbsp;&nbsp;
                       </a></div>
                    </li>
                </li>
            </ul>
        </div>

    </nav>



    <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>

3 个答案:

答案 0 :(得分:2)

尝试以下代码:

选项:1

<li class="nav-item dropdown">
    <div class="sms-button" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
        <a class="nav-link dropdown-toggle" href="#" >&nbsp;SMS&nbsp;&nbsp;</a>
    </div>
    <div class="dropdown-menu" aria-labelledby="navbarDropdown">
        <a class="dropdown-item" href="#">Delivered Status</a>
        <a class="dropdown-item" href="#">Log details</a>
    </div>
</li>

选项:2

<li class="nav-item dropdown">
    <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">&nbsp;Email&nbsp;&nbsp;</a>
    <div class="dropdown-menu" aria-labelledby="navbarDropdown">
        <a class="dropdown-item" href="#">Deivered Status</a>
        <a class="dropdown-item" href="#">Log Status</a>
    </div>
</li>

答案 1 :(得分:0)

这可能是因为你在那里添加了另一个div。

尝试重新排列代码,以便具有类.dropdown-toggle的元素是下一个项目。而不是div.sms-button

答案 2 :(得分:0)

添加数据切换=&#34;崩溃&#34;数据目标=&#34; .navbar合拢&#34;到您的可点击图标

&#13;
&#13;
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
        <script defer src="https://use.fontawesome.com/releases/v5.0.6/js/all.js"></script>
    
        <script src="main.js"></script>

        <nav class="navbar navbar-expand-lg navbar fixed-top navbar-light bg-light">
            <!--code changes here-->
            <span class="navbar-toggler-icon" data-toggle="collapse"  data-target=".navbar-collapse"></span>
            <div class="collapse navbar-collapse" id="navbarSupportedContent">
                <ul class="navbar-nav mr-auto ">
                    <li class="nav-item">
                        <div class="new-pickup"> <a class="nav-link" id="new-pickup" href="#"><i class="fa fa-plus"id="add-plus" aria-hidden="true"></i>
                         New Pickup&nbsp;&nbsp;&nbsp;&nbsp;</a></div>
                        <li class="nav-item dropdown">
                            <div class="sms-button">
                                <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                              &nbsp;SMS&nbsp;&nbsp;
                            </a>
                            </div>
                            <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                                <a class="dropdown-item" href="#">Delivered Status</a>
                                <a class="dropdown-item" href="#">Log details</a>
                            </div>
                        </li>
                        <li class="nav-item dropdown">
                            <div class="email-button">
                                <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                &nbsp;Email&nbsp;&nbsp;
                              </a>
                            </div>
                            <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                                <a class="dropdown-item" href="#">Deivered Status</a>
                                <a class="dropdown-item" href="#">Log Status</a>
                            </div>
                        </li>
                        <li class="nav-item">
                            <div class="call-button">
                                <a class="nav-link" href="#"><i class="fa fa-phone fa-flip-horizontal " aria-hidden="true"></i>
                              Call&nbsp;&nbsp;&nbsp;
                           </a></div>
                        </li>
                    </li>
                </ul>
            </div>
    
        </nav>
    
    
    
        <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>
&#13;
&#13;
&#13;