【发布时间】:2014-01-11 15:32:25
【问题描述】:
我已经阅读了 stackoverflow 上有关导航栏中 dropdown box 的多个线程,但没有一个对我的问题有帮助。
我使用的是 bootstrap 版本 3,我使用的是官方网站上提供的 navbar 示例:
http://getbootstrap.com/components/#navbar
我使用的代码与该网站上的代码完全相同,并且包括以下 javascript 和 css 文件:
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="static/js/transition.js"></script>
<script type="text/javascript" src="static/js/collapse.js"></script>
<script type="text/javascript" src="static/js/dropdown.js"></script>
<script type="text/javascript" src="static/js/bootstrap.js"></script>
<link rel="stylesheet" href="static/css/bootstrap.css" type="text/css">
<link rel="stylesheet" href="static/css/footer.css" type="text/css">
我下载了不同的js 和css 文件,但jquery 文件除外。
我之前得到了这个工作,但即使经过大量的故障排除,现在也没有,当时脚本标签的顺序是错误的。
根据引导网站,jquery 插件是必要的,除了折叠插件依赖于过渡插件(因此放置在折叠插件之前)。然后是dropdown js 和引导程序以及css 文件。
我不明白为什么这不起作用。问题是当我点击dropdown 框时,它根本不显示菜单,什么也没有发生。我尝试了很多不同的配置,但没有任何效果。
我正在使用此代码:
<html
<head>
<title>testing</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="static/js/transition.js"></script>
<script type="text/javascript" src="static/js/collapse.js"></script>
<script type="text/javascript" src="static/js/dropdown.js"></script>
<script type="text/javascript" src="static/js/bootstrap.js"></script>
<link rel="stylesheet" href="static/css/bootstrap.css" type="text/css">
<link rel="stylesheet" href="static/css/footer.css" type="text/css">
</head>
<body>
<nav class="navbar navbar-default" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
<li class="divider"></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</nav>
</body>
</html>
我还尝试用 erikrunia 在他的一个回复中写的代码替换所有导入,这与示例网站上的代码相同。
这是页面在浏览器呈现时的外观:
在站点上运行调试器后,我收到了这些警告/错误,但在访问引导站点本身时我也收到了很多这些,所以我不知道它们是否与实际问题有关:
18:23:45.672 file:///Users/exceed/index.html
18:23:45.673 file:///Users/exceed/static/js/jquery.js
18:23:45.674 file:///Users/exceed/static/js/transition.js
18:23:45.674 file:///Users/exceed/static/js/collapse.js
18:23:45.675 file:///Users/exceed/static/js/dropdown.js
18:23:45.675 file:///Users/exceed/static/js/bootstrap.js
18:23:45.676 file:///Users/exceed/static/css/bootstrap.css
18:23:45.676 file:///Users/exceed/static/css/footer.css
18:23:45.643 Unknown property 'box-sizing'. Declaration dropped. bootstrap.css:93
18:23:45.643 Unknown property 'box-sizing'. Declaration dropped. bootstrap.css:195
18:23:45.643 Unknown property 'box-sizing'. Declaration dropped. bootstrap.css:201
18:23:45.643 Unknown pseudo-class or pseudo-element '-webkit-search-cancel-button'. Ruleset ignored due to bad selector. bootstrap.css:205
18:23:45.644 Unknown property 'box-sizing'. Declaration dropped. bootstrap.css:306
18:23:45.644 Expected color but found 'auto'. Expected color but found '-webkit-focus-ring-color'. Expected end of value but found '-webkit-focus-ring-color'. Error in parsing value for 'outline'. Declaration dropped. bootstrap.css:344
18:23:45.645 Unknown property 'box-sizing'. Declaration dropped. bootstrap.css:1882
18:23:45.645 Expected end of value but found '\9 '. Error in parsing value for 'margin-top'. Declaration dropped. bootstrap.css:1888
18:23:45.645 Expected color but found 'auto'. Expected color but found '-webkit-focus-ring-color'. Expected end of value but found '-webkit-focus-ring-color'. Error in parsing value for 'outline'. Declaration dropped. bootstrap.css:1913
18:23:45.645 Unknown pseudo-class or pseudo-element '-webkit-outer-spin-button'. Ruleset ignored due to bad selector. bootstrap.css:1917
18:23:45.645 Unknown pseudo-class or pseudo-element '-ms-input-placeholder'. Ruleset ignored due to bad selector. bootstrap.css:1965
18:23:45.645 Unknown pseudo-class or pseudo-element '-webkit-input-placeholder'. Ruleset ignored due to bad selector. bootstrap.css:1969
18:23:45.646 Unknown property 'user-select'. Declaration dropped. bootstrap.css:2262
18:23:45.646 Expected color but found 'auto'. Expected color but found '-webkit-focus-ring-color'. Expected end of value but found '-webkit-focus-ring-color'. Error in parsing value for 'outline'. Declaration dropped. bootstrap.css:2267
18:23:45.646 Expected 'none' or URL but found 'alpha('. Error in parsing value for 'filter'. Declaration dropped. bootstrap.css:2291
18:23:45.647 Expected 'none' or URL but found 'progid'. Error in parsing value for 'filter'. Declaration dropped. bootstrap.css:3555
18:23:45.650 Error in parsing value for 'background-image'. Declaration dropped. bootstrap.css:5459
18:23:45.650 Error in parsing value for 'background-image'. Declaration dropped. bootstrap.css:5460
18:23:45.650 Error in parsing value for 'background-image'. Declaration dropped. bootstrap.css:5476
18:23:45.650 Error in parsing value for 'background-image'. Declaration dropped. bootstrap.css:5477
18:23:45.650 Error in parsing value for 'background-image'. Declaration dropped. bootstrap.css:5487
18:23:45.650 Error in parsing value for 'background-image'. Declaration dropped. bootstrap.css:5488
18:23:45.650 Error in parsing value for 'background-image'. Declaration dropped. bootstrap.css:5498
18:23:45.650 Error in parsing value for 'background-image'. Declaration dropped. bootstrap.css:5499
18:23:45.650 Error in parsing value for 'background-image'. Declaration dropped. bootstrap.css:5509
18:23:45.650 Error in parsing value for 'background-image'. Declaration dropped. bootstrap.css:5510
18:23:45.650 Unknown property 'zoom'. Declaration dropped. bootstrap.css:5518
18:23:45.651 Expected 'none' or URL but found 'alpha('. Error in parsing value for 'filter'. Declaration dropped. bootstrap.css:5964
18:23:45.651 Expected 'none' or URL but found 'alpha('. Error in parsing value for 'filter'. Declaration dropped. bootstrap.css:5973
18:23:45.651 Expected 'none' or URL but found 'alpha('. Error in parsing value for 'filter'. Declaration dropped. bootstrap.css:6049
18:23:45.651 Expected 'none' or URL but found 'alpha('. Error in parsing value for 'filter'. Declaration dropped. bootstrap.css:6054
18:23:45.651 Expected 'none' or URL but found 'alpha('. Error in parsing value for 'filter'. Declaration dropped. bootstrap.css:6136
18:23:45.651 Expected 'none' or URL but found 'alpha('. Error in parsing value for 'filter'. Declaration dropped. bootstrap.css:6142
18:23:45.651 Expected 'none' or URL but found 'alpha('. Error in parsing value for 'filter'. Declaration dropped. bootstrap.css:6454
18:23:45.651 Error in parsing value for 'background-image'. Declaration dropped. bootstrap.css:6458
18:23:45.651 Error in parsing value for 'background-image'. Declaration dropped. bootstrap.css:6459
18:23:45.651 Expected 'none' or URL but found 'progid'. Error in parsing value for 'filter'. Declaration dropped. bootstrap.css:6463
18:23:45.651 Error in parsing value for 'background-image'. Declaration dropped. bootstrap.css:6469
18:23:45.651 Error in parsing value for 'background-image'. Declaration dropped. bootstrap.css:6470
18:23:45.651 Expected 'none' or URL but found 'progid'. Error in parsing value for 'filter'. Declaration dropped. bootstrap.css:6474
18:23:45.651 Expected 'none' or URL but found 'alpha('. Error in parsing value for 'filter'. Declaration dropped. bootstrap.css:6482
18:23:45.651 Expected end of value but found '\9 '. Error in parsing value for 'background-color'. Declaration dropped. bootstrap.css:6541
18:23:45.658 TypeError: $(...).on is not a function collapse.js:160
18:23:45.659 TypeError: $(...).on is not a function dropdown.js:149
18:23:45.661 TypeError: $(...).on is not a function bootstrap.js:163
18:23:45.662 The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol. index.html
【问题讨论】:
-
我认为 bootstrap.js 应该在 transition.js 之上。还可以尝试将两个 CSS 导入移到所有内容之上
-
我在 jquery 之后添加了 bootstrap.js 但仍然没有运气。当我转到示例站点时,当我单击保管箱时它可以工作,所以仍然有问题
-
我会按 f12 并查看您的控制台中是否出现任何错误。可能是 .js 文件的路径错误,根本没有加载。
-
我使用了 firebug 并检查了访问日志,找到了它们(状态 200/304).. 我总是在 chrome 中使用 cmd+r 使其查询服务器以检查文件是否更新而不是直接从浏览器返回缓存数据
-
发布你的 html 来构建带有下拉菜单的导航栏
标签: javascript jquery html css twitter-bootstrap