我发现我的下拉菜单(HOME CCTV)无效。 任何帮助都可以得到赞赏。 是新手。 下拉链接非常有用。
<nav class="navbar navbar-expand-lg">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon">
<div class="bar1"></div>
<div class="bar2"></div>
<div class="bar3"></div>
</span>
</button>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="index.html">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="home-cctv-intro.html" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Home CCTV
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="home-cctv-intro.html">Introduction</a>
<a class="dropdown-item" href="home-cctv-footage.html">Footage</a>
<a class="dropdown-item" href="home-cctv-cost.html">Costs</a>
<a class="dropdown-item" href="home-cctv-quote.html">Get a Quote</a>
</div>
</li>
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" crossorigin="anonymous"></script>
用于下拉悬停链接的JS文件
$('body').on('mouseenter mouseleave','.dropdown',function(e){
var _d=$(e.target).closest('.dropdown');_d.addClass('show');
setTimeout(function(){
_d[_d.is(':hover')?'addClass':'removeClass']('show');
},300);
});
答案 0 :(得分:-1)
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("li.dropdown").hover(function(){
$(this).toggleClass("show");
$('.dropdown-menu').toggleClass("show");
$('.nav-link.dropdown-toggle').attr('aria-expanded' , 'true');
});
});
</script>
</head>
<body>
<nav class="navbar navbar-expand-lg">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon">
<div class="bar1"></div>
<div class="bar2"></div>
<div class="bar3"></div>
</span>
</button>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="index.html">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="home-cctv-intro.html" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Home CCTV
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="home-cctv-intro.html">Introduction</a>
<a class="dropdown-item" href="home-cctv-footage.html">Footage</a>
<a class="dropdown-item" href="home-cctv-cost.html">Costs</a>
<a class="dropdown-item" href="home-cctv-quote.html">Get a Quote</a>
</div>
</li>
</ul>
</div>
</nav>
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.6/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script>
</body>
</html>