gpt4 book ai didi

javascript - Bootstrap 汉堡包在切换后不显示列表元素

转载 作者:行者123 更新时间:2023-11-28 16:03:19 26 4
gpt4 key购买 nike

我正在尝试将 Bootstrap 的汉堡菜单合并到页面上,但似乎无法在切换后显示列表元素。

菜单在桌面上加载良好并且确实隐藏了链接,显示了汉堡包。但是,在点击汉堡包图标时,没有任何反应?

示例:

ul {
list-style-type: none;
}

li {
padding: 0px 30px;
}
<!-- BOOTSTRAP -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>


<div class="navbar navbar_container">
<div class="navbar_container-wrapper">

<nav class="navbar navbar-inverse navbar-static-top" role="navigation">

<div class="navbar_wrapper-list container">

<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#hamburger">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>

<div class="collapse navbar-collapse" id="hamburger">

<ul class="navbar_wrapper-ul navbar-nav mr-auto">
<li id="list-item-1" class="navbar_wrapper-li active nav-item"><a class="active" href="#">Home</a></li>
<li id="list-item-2" class="navbar_wrapper-li nav-item"><a class="nav-link" href="#">Blog</a></li>
<li id="list-item-3" class="navbar_wrapper-li nav-item"><a class="nav-link" href="#">Portfolio</a></li>
<li id="list-item-4" class="navbar_wrapper-li nav-item"><a class="nav-link" href="#">Contact</a></li>
</ul>

</div>
</div>
<!-- .navbar_wrapper-list end -->
</nav>
</div>
<!-- .navbar_container-wrapper end -->
</div>
<!-- .navbar-container end-->

这个CodePen采用了我的方法.

最佳答案

Actually you need to add "jquery.min.js" before "bootstrap.min.js". Because "bootstrap.min.js" depends on "jquery.min.js"

ul {
list-style-type: none;
}

li {
padding: 0px 30px;
}
<!-- BOOTSTRAP -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">



<div class="navbar navbar_container">
<div class="navbar_container-wrapper">

<nav class="navbar navbar-inverse navbar-static-top" role="navigation">

<div class="navbar_wrapper-list container">

<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#hamburger">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>

<div class="collapse navbar-collapse" id="hamburger">

<ul class="navbar_wrapper-ul navbar-nav mr-auto">
<li id="list-item-1" class="navbar_wrapper-li active nav-item"><a class="active" href="#">Home</a></li>
<li id="list-item-2" class="navbar_wrapper-li nav-item"><a class="nav-link" href="#">Blog</a></li>
<li id="list-item-3" class="navbar_wrapper-li nav-item"><a class="nav-link" href="#">Portfolio</a></li>
<li id="list-item-4" class="navbar_wrapper-li nav-item"><a class="nav-link" href="#">Contact</a></li>
</ul>

</div>
</div>
<!-- .navbar_wrapper-list end -->
</nav>
</div>
<!-- .navbar_container-wrapper end -->
</div>
<!-- .navbar-container end-->

关于javascript - Bootstrap 汉堡包在切换后不显示列表元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53612240/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com