admin管理员组文章数量:1341740
I am having some problems making twitter bootstrap drop-down navbar work. I ran through numerous tutorials and if I copy the code from there it doesn't work for me. In the console I get the following error
TypeError: $ is undefined
var old = $.fn.dropdown
Here is my code:
<div class="container-fluid">
<div class="row-fluid">
<div class="span8">
<!--Body content-->
<div class="navbar">
<div class="navbar-inner">
<ul id="tab" class="nav">
<li class="active"><a href="#Tab1" data-toggle="tab">Recent</a></li>
<li><a href="#Tab2" data-toggle="tab">Top</a></li>
<li><a href="#Tab3" data-toggle="tab">Near you</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Filters <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Filter1</a></li>
<li><a href="#">Filter2</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
<div class="span4">
<!--Sidebar content-->
</div>
</div>
</div>
And here are my includes - they load without problem:
<link href="bootstrap/css/bootstrap.css" rel="stylesheet" media="screen">
<script type="text/javascript" src="bootstrap/js/bootstrap-dropdown.js"></script>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
The page loads up, but when I click on the Filters menu item, it throws the above mentioned exception and nothing happens.
I am having some problems making twitter bootstrap drop-down navbar work. I ran through numerous tutorials and if I copy the code from there it doesn't work for me. In the console I get the following error
TypeError: $ is undefined
var old = $.fn.dropdown
Here is my code:
<div class="container-fluid">
<div class="row-fluid">
<div class="span8">
<!--Body content-->
<div class="navbar">
<div class="navbar-inner">
<ul id="tab" class="nav">
<li class="active"><a href="#Tab1" data-toggle="tab">Recent</a></li>
<li><a href="#Tab2" data-toggle="tab">Top</a></li>
<li><a href="#Tab3" data-toggle="tab">Near you</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Filters <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Filter1</a></li>
<li><a href="#">Filter2</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
<div class="span4">
<!--Sidebar content-->
</div>
</div>
</div>
And here are my includes - they load without problem:
<link href="bootstrap/css/bootstrap.css" rel="stylesheet" media="screen">
<script type="text/javascript" src="bootstrap/js/bootstrap-dropdown.js"></script>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
The page loads up, but when I click on the Filters menu item, it throws the above mentioned exception and nothing happens.
Share edited Dec 28, 2012 at 15:46 Praveen Kumar Purushothaman 167k27 gold badges213 silver badges260 bronze badges asked Dec 28, 2012 at 15:45 PioPio 4,06211 gold badges47 silver badges81 bronze badges 01 Answer
Reset to default 11You must change the order javascripts are included. JQuery must e before bootstrap.
<link href="bootstrap/css/bootstrap.css" rel="stylesheet" media="screen">
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="bootstrap/js/bootstrap-dropdown.js"></script>
EDIT, the why: Javascript is executed as soon as it gets loaded. At the time bootstrap-dropdown.js is being parsed, jQuery should have been already loaded. That way jQuery functionality will be available to bootstrap-dropdown.
本文标签: javascriptTwitter bootstrap navbar dropdownStack Overflow
版权声明:本文标题:javascript - Twitter bootstrap navbar dropdown - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743682130a2521302.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论