Navbar下拉列表无法在我的本地服务器上运行

时间:2014-11-26 14:01:10

标签: html css jquery-ui twitter-bootstrap-3

我刚开始使用bootstrap并试图在我的本地服务器上进行一些模拟布局。事情进展顺利,直到我无法让导航栏在我的模拟页面上工作。我已经检查了野生动物园和铬,结果仍然是相同的。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap 101 Template</title>

<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
 <body>
  <div class= "navbar navbar-inverse navbar-fixed-top" role= "navigation">
    <div class= "container">
      <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle= "collapse" data-target=".navbar-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" href="#">Bootstrap Practice</a>
    </div>
      <div class="navbar-collapse collapse">
        <ul class="nav navbar-nav navbar-right">
          <li class= "active"> <a href="#"> Home</a></li>
          <li > <a href="#about"> About </a></li>
          <li > <a href="#"> Blog</a></li>
          <li > <a href="#"> Contact Us</a></li>
          <li class=  "dropdown">
              <a href="#" class= "dropdown-toggle" data-toggle=" dropdown">Themes <b class="caret"></b></a>
              <ul class="dropdown-menu">
                <li class= "dropdown-header">Dashboard</li>
                    <li><a href="#"> Admin 1</a></li>
                    <li><a href="#"> Admin 2</a></li>
                    <li class="divider"></li>
                  </li>
              </ul>
          </li>
        </ul>
      </div>
    </div>
  </div>

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>

2 个答案:

答案 0 :(得分:1)

将你的代码弹出到Bootply中,我唯一看不到的就是你的下拉列表在点击时没有下降。

你的问题就在这一行:

<a href="#" class= "dropdown-toggle" data-toggle=" dropdown">Themes <b class="caret"></b></a>

查看data-toggle属性中的额外空间?删除它,你的下拉列表工作正常。

您的下拉列表中还有一个额外的</li>标记。不会破坏,但不需要。

<强> BOOTPLY

<强> HTML:

<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
    <div class="container">
      <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-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" href="#">Bootstrap Practice</a>
    </div>
      <div class="navbar-collapse collapse">
        <ul class="nav navbar-nav navbar-right">
          <li class="active"> <a href="#"> Home</a></li>
          <li> <a href="#about"> About </a></li>
          <li> <a href="#"> Blog</a></li>
          <li> <a href="#"> Contact Us</a></li>
          <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown">Themes <b class="caret"></b></a>
              <ul class="dropdown-menu">
                <li class="dropdown-header">Dashboard</li>
                    <li><a href="#"> Admin 1</a></li>
                    <li><a href="#"> Admin 2</a></li>
                    <li class="divider"></li>
              </ul>
          </li>
        </ul>
      </div>
    </div>
  </div>

答案 1 :(得分:0)

你有错误 <a href="#" class= "dropdown-toggle" data-toggle=" dropdown">Themes <b class="caret"></b></a>

解决方案是:

<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Themes<span class="caret"></span></a>

这里的例子是:

Fixed example

<div class= "navbar navbar-inverse navbar-fixed-top" role= "navigation">
    <div class= "container">
      <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle= "collapse" data-target=".navbar-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" href="#">Bootstrap Practice</a>
    </div>
      <div class="navbar-collapse collapse">
        <ul class="nav navbar-nav navbar-right">
          <li class= "active"> <a href="#"> Home</a></li>
          <li> <a href="#about"> About </a></li>
          <li> <a href="#"> Blog</a></li>
          <li> <a href="#"> Contact Us</a></li>

            <li class=  "dropdown">
             <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Themes<span class="caret"></span></a>

              <ul class="dropdown-menu">
                <li class= "dropdown-header">Dashboard</li>
                    <li><a href="#"> Admin 1</a></li>
                    <li><a href="#"> Admin 2</a></li>
                    <li class="divider"></li> 
                    <li><a href="#"> Admin 3</a></li>           
              </ul>
            </li>                
          </ul>
      </div>
    </div>
</div><!-- navbar -->