为什么我的导航栏上没有折叠的视图按钮?

时间:2015-07-26 23:04:01

标签: html css twitter-bootstrap navbar

Bootstrap提供以下代码用作导航栏。但是,当我只是粘贴代码而不改变它时,折叠的视图不起作用。当您将浏览器窗口调整为更窄时,导航栏将变为一个按钮,您可以单击该按钮再次显示所有导航组件。但是,当我只是粘贴代码时,它似乎无法正常工作。谁知道为什么?导航组件确实已折叠,但单击按钮显示它们并没有做任何事情。

lodash

HTML

<nav class="navbar navbar-default">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <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 <span class="sr-only">(current)</span></a></li>
        <li><a href="#">Link</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></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 role="separator" class="divider"></li>
            <li><a href="#">Separated link</a></li>
            <li role="separator" 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" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></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 role="separator" class="divider"></li>
            <li><a href="#">Separated link</a></li>
          </ul>
        </li>
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>

配置/ js.php

<?php include('config/setup.php'); ?>   

<!DOCTYPE html>
<html lang="en">    

    <head> 
        <meta charset="utf-8" />
        <title>Search Hound</title>

        <!--This enables the website to be mobile first-->
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <?php include('config/js.php'); ?>

        <?php include('config/css.php'); ?>



    </head>

    <body>

        <?php include('template/navigation.php'); ?>

        <div class="container">
         <form class="form-inline" align="center">

        <!-- Section to type question-->
            <div class="form-group" style="display:block">
                <textarea class="form-control" style="width:100%" rows="5"></textarea>
            </div>

        <!--Section to add money-->
            <div class="input-group" id="AddMoney">
              <span class="input-group-addon">$</span>
              <input id="EnterMoney" type="text" class="form-control" onkeypress='validate(event)' aria-label="Amount (in dollars and cents)">
            </div>

        <!--Section to add file-->
            <div id="AddFile">
                <a href="#" onclick="document.getElementById('uploadFile').click(); return false;">Add File</a>
                <input type="file" id="uploadFile" style="visibility: hidden;" />
            </div>

            <div id="imagePreview"></div>

        <!--Section for the Submit button-->
            <div>
                <button type="submit" class="btn btn-primary">Submit</button>
            </div>
        </form>
        </div>
        <!-- /container -->

    <div

    </body>

    <?php include('template/footer.php'); ?>

</html>

2 个答案:

答案 0 :(得分:1)

我没有看到你在bootstrap.js文件之前包含jQuery。 jQuery需要使用bootstrap javascript组件。

在您的bootstrap.js文件中添加此config/js.php

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

答案 1 :(得分:0)

如果我理解你的问题,这就是你想要的:

Jquery的:

$(".navbar-toggle").click(function(){
    $(".navbar").slideToggle();
});

http://jsfiddle.net/xz06armf/