twitter-bootstrap Bootstrap 3 下拉菜单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18679944/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bootstrap 3 Dropdown Menu
提问by Yahiko Kikikoto
Despite the many, many tutorials I have searched through, the dropdown feature of my navigation bar is not functioning. Please help if you know some sort of difference with multidimensional dropdown menus in Bootstrap 3 that I am not seeing.
尽管我搜索了许多教程,但导航栏的下拉功能不起作用。如果您知道我没有看到的 Bootstrap 3 中的多维下拉菜单的某种差异,请提供帮助。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content=
"HTML Tidy for Linux/x86 (vers 25 March 2009), see www.w3.org" />
<title>Bootstrap 101 Template</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen" type="text/css" />
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="../../assets/js/html5shiv.js"></script>
<script src="../../assets/js/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="navbar-header">
<a class="navbar-brand" href="#">Brand</a>
</div>
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">The Artists</a></li>
<li><a href="#">The Art</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Schedule</a>
<ul class="dropdown-menu">
<li><a href="#">Day One</a></li>
<li><a href="#">Day Two</a></li>
<li><a href="#">Day Three</a></li>
</ul>
</li>
<li><a href="#">Venue</a></li>
<li><a href="#">Hotels</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input class="form-control" type="text" placeholder="Search" />
</div><button style="margin-left: 5px;" class="btn btn-default" type=
"submit">Submit</button>
</form>
</li>
</ul>
</div>
</body>
</html>
回答by Phil Nicholas
There's a lot of things going on with your file:
您的文件有很多事情要做:
- Your doctype is wrong. You're specifying XHTML 1.0, when you should be just using the HTML5 declaration.
- As @sbat pointed out above, you're missing the Bootstrap script file.
- 你的文档类型是错误的。您正在指定 XHTML 1.0,而您应该只使用 HTML5 声明。
- 正如@sbat 上面指出的那样,您缺少 Bootstrap 脚本文件。
I've completely formatted your template below, per the usual tutorials. Let me know if you have any questions or need anything else.
根据通常的教程,我已经在下面完全格式化了您的模板。如果您有任何问题或需要其他任何东西,请告诉我。
UPDATE: Here's link to your menu in JSFiddle
更新:这是您在JSFiddle 中菜单的链接
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="HTML Tidy for Linux/x86 (vers 25 March 2009), see www.w3.org" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Bootstrap Menu Sample</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="js/jquery.js"></script>
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<div class="navbar navbar-static-top" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<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" rel="home" href="/" title="Aahan Krish's Blog - Homepage">Brand</a>
</div>
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">The Artists</a></li>
<li><a href="#">The Art</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Schedule <b class="caret"></b></a>
<ul class="dropdown-menu unstyled pull-left dropdown-features">
<li><a href="#">Day One</a></li>
<li><a href="#">Day Two</a></li>
<li><a href="#">Day Three</a></li>
</ul>
</li>
<li><a href="#">Venue</a></li>
<li><a href="#">Hotels</a></li>
</ul>
<div class="col-sm-3 col-md-3 pull-right">
<form class="navbar-form" role="search">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search" name="srch-term" id="srch-term">
<div class="input-group-btn">
<button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
</form>
</div>
</div>
</body>
</html>
回答by sgbj
You do realize the dropdown functionality (and several other features) requires Bootstrap's JS file right (which in turn requires jQuery)? I don't see a reference to it, you could try adding these script tags at the bottom of your body tag:
您确实意识到下拉功能(和其他几个功能)需要 Bootstrap 的 JS 文件(这又需要 jQuery)吗?我没有看到对它的引用,您可以尝试在 body 标签的底部添加这些脚本标签:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>

