导航栏Dropdown无响应故障求助:排查与解决方案咨询
Hey there! Let's troubleshoot why your Bootstrap dropdown isn't working—here are the key issues and fixes to get it functional again:
You're loading two different versions of jQuery on your page: a full version (jquery/3.3.1/jquery.min.js) and a slim version (jquery-3.3.1.slim.min.js). The slim version removes core modules that Bootstrap's dropdown relies on (like $.fn.dropdown), and duplicate jQuery loads cause JS context conflicts that break dropdown bindings entirely.
Fix:
Remove one of the jQuery imports—stick with the full version since the slim build lacks necessary functionality. Make sure jQuery loads before Bootstrap's JS. Your corrected script order should look like this:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
Your custom nav ul CSS includes overflow: hidden, which cuts off the dropdown menu (it's absolutely positioned outside the bounds of the ul by default). This is why you don't see any content when clicking the dropdown button.
Fix:
Remove the overflow: hidden property from nav ul:
nav ul { line-height: 60px; list-style: none; background: rgba(0, 0, 0, 0); /* Remove overflow: hidden; */ color: #fff; padding: 0; text-align: right; margin: 0; padding-right: 40px; transition: 1s; }
This ensures the dropdown menu can render outside the ul container without being hidden.
Your initial jQuery code for the burger menu uses $("menu-icon") instead of $(".menu-icon")—you missed the class selector dot. This would break the mobile menu toggle too. Correct it like this:
$(document).ready(function() { $(".menu-icon").on("click", function() { $("nav ul").toggleClass("showing"); }); });
Here's the integrated fixed code for your reference:
HTML (Navigation Section)
<nav> <div class="menu-icon"> <i class="fa fa-bars fa-2x"></i> </div> <div class="logo"> <img src="../img/logo.png" style="height:60px;" alt="Site Logo"> </div> <div class="menu"> <ul> <li><a href="../index.html">Home</a></li> <li><a href="team.html">Link#2</a></li> <li> <div class="dropdown"> <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> Dropdown button </button> <div class="dropdown-menu" aria-labelledby="dropdownMenuButton"> <a class="dropdown-item" href="#">Action</a> <a class="dropdown-item" href="#">Another action</a> <a class="dropdown-item" href="#">Something else here</a> </div> </div> </li> <li><a href="blog.html">Link#4</a></li> <li><a href="cont.html">Link#5</a></li> </ul> </div> </nav> <div class="demo"></div>
CSS (Key Modified Rules)
nav ul { line-height: 60px; list-style: none; background: rgba(0, 0, 0, 0); color: #fff; padding: 0; text-align: right; margin: 0; padding-right: 40px; transition: 1s; /* Removed overflow: hidden */ } /* Keep your other CSS rules unchanged */
Scripts (Final Order)
<!-- Place these at the bottom of your body tag --> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script> <!-- Add Font Awesome to display the burger icon --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
内容的提问来源于stack exchange,提问作者Boombaar

