简体   繁体   English

Twitter引导程序导航栏下拉列表

[英]Twitter bootstrap navbar dropdown

I am having some problems making twitter bootstrap drop-down navbar work. 我在使用twitter bootstrap下拉导航栏工作时遇到了一些问题。 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. 页面加载,但是当我单击Filters菜单项时,它会抛出上面提到的异常并且没有任何反应。

You must change the order javascripts are included. 您必须更改包含javascripts的顺序。 JQuery must come before bootstrap. JQuery必须在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. 编辑,原因:Javascript在加载后立即执行。 At the time bootstrap-dropdown.js is being parsed, jQuery should have been already loaded. 在解析bootstrap-dropdown.js时,应该已经加载了jQuery。 That way jQuery functionality will be available to bootstrap-dropdown. 这样jQuery功能将可用于bootstrap-dropdown。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM