下拉菜单无法在标题中使用

时间:2022-02-22 20:11:41

I have a very simple bootstrap header. The only issue with it is that the dropdown menu in the header does not drop down... I will post my code below

我有一个非常简单的bootstrap头。唯一的问题是标题中的下拉菜单没有下拉...我将在下面发布我的代码

Code:

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />

<!-- Font awesome reference -->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" />

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

<nav class="navbar navbar-default 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="#">My Project</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
                <li class="active"><a href="#">Home</a></li>
                <li><a href="#">Contact</a></li>
                <li runat="server" class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown<b class="caret"></b></a>
                    <ul class="dropdown-menu">
                        <li><a href="#">Menu Item 1</a></li>
                        <li><a href="#">Menu Item 2</a></li>
                        <li><a href="#">Menu Item 3</a></li>
                        <li><a href="#">Menu Item 4</a></li>
                    </ul>
                </li>
            </ul>              
        </div>
        <!--/.nav-collapse -->
    </div>
</nav>

I know this is a lot of code to post, just wanted to make sure nothing was left out.

我知道这是要发布的很多代码,只是想确保没有遗漏任何内容。

1 个解决方案

#1


2  

You need to link the JQuery for dropdown menu to work. Add it before bootstrap.min.js.

您需要链接JQuery for下拉菜单才能工作。在bootstrap.min.js之前添加它。

After adding JQuery it goes like this.

添加JQuery后就像这样。

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />

<!-- Font awesome reference -->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" />

<!-----add this JQuery before bootstrap.min.js----->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.min.js"></script>

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

Hope this help.!

希望这有帮助。!

#1


2  

You need to link the JQuery for dropdown menu to work. Add it before bootstrap.min.js.

您需要链接JQuery for下拉菜单才能工作。在bootstrap.min.js之前添加它。

After adding JQuery it goes like this.

添加JQuery后就像这样。

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />

<!-- Font awesome reference -->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" />

<!-----add this JQuery before bootstrap.min.js----->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.min.js"></script>

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

Hope this help.!

希望这有帮助。!