1

尽管我搜索了很多很多教程,但我的导航栏的下拉功能不起作用。如果您知道我没有看到的 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>
4

2 回答 2

5

您的文件发生了很多事情:

  • 你的文档类型是错误的。您正在指定 XHTML 1.0,而您应该只使用 HTML5 声明。
  • 正如@sbat 上面指出的那样,您缺少 Bootstrap 脚本文件。

根据通常的教程,我已在下面完全格式化了您的模板。如果您有任何问题或需要其他任何东西,请告诉我。

更新:这是您在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>
于 2013-09-08T03:30:53.600 回答
2

您确实意识到下拉功能(以及其他几个功能)需要正确的 Bootstrap JS 文件(这又需要 jQuery)?我没有看到对它的引用,您可以尝试在正文标签的底部添加这些脚本标签:

<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>
于 2013-09-08T03:21:30.060 回答