导航栏下拉菜单不起作用 Bootstrap 下拉锚点在点击时不起作用

navbar dropdown not working Bootstrap Dropdown anchor not working on click

我正在尝试使用 bootstrap 构建带下拉菜单的导航栏。 但是当我单击内容按钮时,下拉菜单不起作用。我想我已经包含了 bootstrap CDN link、bootstrap css link、css link 和 jquery link 在代码的正确位置。 我加了一点CSS

我现在放一个视频link,稍后我会添加另一个页面。我想要点击下拉操作

这是一个片段

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>topMenu</title>
    <link rel="stylesheet" type="text/css" href="../resources/css/topMenu.css"/>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.2/css/all.min.css"/>
    
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    
</head>
<body>
    <nav class="navbar navbar-inverse navbar-fixed-top">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                    <li class="logo"><a href="${path}/#home"><img src="../resources/css/frontLogo.png" ></a></li>
            </div>
            
            <div>
                <div class="collapse navbar-collapse" id="myNavbar">
                    <ul class="nav navbar-nav navbar-right">
                    
                        <li class="item"><a href="${path }/#home"><b>Home</b></a></li>
                        <li class="item"><a href="${path }/#about">About</a></li>
                        <li class="item"><a href="${path}/news/newsList">News</a></li>  
                        
                        
                        <li class="dropdown">
                            <a class="dropdown-toggle" data-toggle="dropdown" href="#">Contents
                            <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu">
                            <li><a href="https://www.youtube.com/channel/UCMpp2Ln-XtD36-iUL3Yd1rw" target="_blank">Videos</a></li>
                        </ul>
                        </li>
                        
                        


                        
                    </ul>
                </div>
            </div>
        </div>
    </nav>

</body>
</html>

CSS 在这里:

* {
    box-sizing: border-box;
    padding: 0;
    margin: 0;    
}

body {
    font-family: sans-serif; 
    background: rgb(13,13,13); 
  }


.navbar {
    background: rgb(27, 27, 27);
}
.nav li > a {
    color: white !important;
}

a:hover {
    text-decoration: underline; 
    
}
.logo img{
    margin-top:5px;
    margin-left:-5px;
    display:block;
    width:50px;
    
  }
  
#myNavbar {
    font-size: 15px;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>topMenu</title>
    
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
   
   <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ" crossorigin="anonymous"></script>
   
</head>
<body>
   
   <nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="${path}/#home"><img src="../resources/css/frontLogo.png" ></a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarScroll" aria-controls="navbarScroll" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarScroll">
      <ul class="navbar-nav me-auto my-2 my-lg-0 navbar-nav-scroll" style="--bs-scroll-height: 100px;">
        <li class="nav-item"><a class="nav-link" href="${path }/#home"><b>Home</b></a></li>
                        <li class="nav-item"><a class="nav-link" href="${path }/#about">About</a></li>
                        <li class="nav-item"><a class="nav-link" href="${path}/news/newsList">News</a></li>
        <li class="nav-item dropdown">
          <a class="nav-link dropdown-toggle" href="#" id="navbarScrollingDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
            Link
          </a>
          <ul class="dropdown-menu" aria-labelledby="navbarScrollingDropdown">
          <li><a class="dropdown-item" href="https://www.youtube.com/channel/UCMpp2Ln-XtD36-iUL3Yd1rw" target="_blank">Videos</a></li>
          </ul>
        </li>
      </ul>
    </div>
  </div>
</nav>

</body>
</html>