问题
I am building website based in django. I am using bootstrap dropdown in navbar to collapse navbar on low resolution i.e. mobile view, but on clicking button navbar not getting dropdown.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<nav id="main-menu" class="navbar" role="navigation">
<div class="navbar-header">
<button type="button" class="btn btn-navbar navbar-toggle" data-toggle="collapse"
data-target=".navbar-cat-collapse">
<span class="sr-only">Toggle Navigation</span>
<i class="fa fa-bars"></i>
</button>
</div>
<div class="collapse navbar-collapse navbar-cat-collapse">
<ul class="nav navbar-nav">
<li><a href="{% url 'home_page' %}">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Pages</a></li>
<li><a href="{% url 'contact_page' %}">Contact Us</a></li>
</ul>
</div>
</nav>
回答1:
as far as I know bootstrap uses its own javascript
library for doing animated stuff like collapsing and so on. so you need to import their js
file as well.
put this line below your first <script>
tag
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
note that because bootstrap js library uses jquery
, you must put this line below importing jquery. otherwise it won't work.
来源:https://stackoverflow.com/questions/41415746/django-bootstrap-dropdown-not-working