当我点击菜单项时,菜单不会关闭。我已经检查了JS和CSS的导入,看起来一切正常,运行菜单还需要做些什么吗?
<!-- Fixed navbar -->
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active"><a href="#home" class="active scroll">Home</a></li>
<li><a href="#about" class="scroll">Sobre</a></li>
<li><a href="#services" class="scroll">Serviços</a></li>
<li><a href="#testimonials" class="scroll">Opiniões</a></li>
<li><a href="#gallery" class="scroll">Gallery</a></li>
<li><a href="#news" class="scroll">News</a></li>
<li><a href="#contact" class="scroll">Contact</a></li>
</ul>
</div>
</div>
</nav>
答案 0 :(得分:2)
对我而言......
$(document).ready(function(){
$('.navbar-collapse a').on('click', function(){
$('.navbar-toggle').click();
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active"><a href="#home" class="active scroll">Home</a></li>
<li><a href="#about" class="scroll">Sobre</a></li>
<li><a href="#services" class="scroll">Serviços</a></li>
<li><a href="#testimonials" class="scroll">Opiniões</a></li>
<li><a href="#gallery" class="scroll">Gallery</a></li>
<li><a href="#news" class="scroll">News</a></li>
<li><a href="#contact" class="scroll">Contact</a></li>
</ul>
</div>
</div>
</nav>
答案 1 :(得分:1)
我不确定,但我认为它可能依赖于jquery ui ...一些引导功能。对目前对这个问题的了解,我无能为力...... 我在进口方面遇到了很多麻烦..你可以尝试检查你的浏览器调试控制台以确保所有内容都正在加载,同样..在chrome:f12,标签源上。
我希望它有所帮助。
答案 2 :(得分:1)
Try It, I think, it usefull.
<nav class="navbar navbar-static-top">
<div>
<div class="navbar-header" >
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar_logistic" aria-expanded="false" aria-controls="navbar" id="button_menu_toggle">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar line_orange"></span>
<span class="icon-bar line_orange"></span>
<span class="icon-bar line_orange"></span>
</button>
</div>
<div id="navbar_logistic" class="navbar-collapse collapse">
<ul class="nav navbar-nav flot_none">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Home2</a></li>
<li><a href="#">Home3</a></li>
<li><a href="#">Home4</a></li>
</ul>
</div>
</div>
</nav>
答案 3 :(得分:1)
检查出来
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script>
<body>
<!-- Fixed navbar -->
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#myNavbar" aria-expanded="false">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active"><a href="#home" class="active scroll">Home</a></li>
<li><a href="#about" class="scroll">Sobre</a></li>
<li><a href="#services" class="scroll">Serviços</a></li>
<li><a href="#testimonials" class="scroll">Opiniões</a></li>
<li><a href="#gallery" class="scroll">Gallery</a></li>
<li><a href="#news" class="scroll">News</a></li>
<li><a href="#contact" class="scroll">Contact</a></li>
</ul>
</div>
</div>
</nav>
</body>
&#13;