jQuery顺序是正确的,因为我在jQuery之后称为bootstrap.js
,但navbar
不起作用。你能帮忙,为什么那不起作用?
<nav class="navbar navbar-default navbar navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="myNavbar">
<span class="icon-bar top-bar"> </span>
<span class="icon-bar middle-bar"> </span>
<span class="icon-bar bottom-bar"> </span>
</button>
<a class="navbar-brand" href="#">home</a>
</div>
<div class="bar collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li> <a class="navbar-brand" href="index.php"> Home </a> </li>
<li> <a class="navbar-brand" href="About.php"> About </a> </li>
<li> <a class="navbar-brand" href="contact.php"> Contact </a> </li>
</ul>
</div>
</div>
</nav>
答案 0 :(得分:1)
#
属性中缺少data-target
。
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="myNavbar">
// -----------------------------------------------------------------------------^^^^
It should be #myNavbar
以下代码应该有效。
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar top-bar"> </span>
<span class="icon-bar middle-bar"> </span>
<span class="icon-bar bottom-bar"> </span>
</button>
<a class="navbar-brand" href="#"> home </a>
</div>
<div class="bar collapse navbar-collapse" id="myNavbar" >
<ul class="nav navbar-nav">
<li> <a class="navbar-brand" href="index.php"> Home </a> </li>
<li> <a class="navbar-brand" href="About.php"> About </a> </li>
<li> <a class="navbar-brand" href="contact.php"> Contact </a> </li>
</ul>
</div>
</div>
</nav>