Twitter bootstrap 引导下拉列表不工作或无法切换

Twitter bootstrap 引导下拉列表不工作或无法切换,twitter-bootstrap,Twitter Bootstrap,我是新手。请告诉我这个代码有什么问题,因为我似乎无法使我的下拉列表或切换工作。多谢各位 <!DOCTYPE html> <html> <head> <title>Red Stone One Stop Shop</title> <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css " /> <link rel="sty

我是新手。请告诉我这个代码有什么问题,因为我似乎无法使我的下拉列表或切换工作。多谢各位

<!DOCTYPE html>
<html>
<head>
    <title>Red Stone One Stop Shop</title>
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css " />
    <link rel="stylesheet" type="text/css" href="css/main.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1,user-scaleable=no">
    <script src="https://ajax.googleapis.com/libs/jquery/2.1.3/jquery.min.js">  
    </script>
    <script src="js/bootstrap.min.js"></script>
</head>
<body>
    <nav class="navbar navbar-default navbar-fixed-top">
    <div class="container">
        <a href="/ecommerce/index.php" class="navbar-brand">Red Stone One Stop Shop</a>
        <ul class="nav navbar-nav">
            <!-- Dropdown menu -->
            <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown" id="text">Men  <span class="caret"></span></a>
                <ul class="dropdown-menu" role="menu">
                    <li><a href="#">Shirts</a></li>
                    <li><a href="#">Pants</a></li>
                    <li><a href="#">Shoes</a></li>
                    <li><a href="#">Accessories</a></li>
                </ul>
            </li>
        </ul>
    </div>
</nav>
</body>
</html>

红石一站式商店

我已经在JSBin中完成了您的示例,它工作正常

您使用的jQuery版本似乎太旧了

更改此项:

<script src="https://ajax.googleapis.com/libs/jquery/2.1.3/jquery.min.js">  

为此:

<script src="https://code.jquery.com/jquery-3.1.0.js"></script>


希望能有所帮助。

你应该做的第一件事是从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">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <title>Red Stone One Stop Shop</title>

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

    <link rel="stylesheet" type="text/css" href="css/main.css" />

    <!-- 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.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>
    <nav class="navbar navbar-default navbar-fixed-top">
      <div class="container">
          <a href="/ecommerce/index.php" class="navbar-brand">Red Stone One Stop Shop</a>
          <ul class="nav navbar-nav">
             <!-- Dropdown menu -->
             <li class="dropdown">
               <a href="#" class="dropdown-toggle" data-toggle="dropdown" id="text">Men  <span class="caret"></span></a>
               <ul class="dropdown-menu" role="menu">
                  <li><a href="#">Shirts</a></li>
                  <li><a href="#">Pants</a></li>
                  <li><a href="#">Shoes</a></li>
                  <li><a href="#">Accessories</a></li>
               </ul>
             </li>
          </ul>
      </div>
    </nav>

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

红石一站式商店
检查工作示例:


但是代码中的问题是jquery版本很旧,只需将其更新为类似于
https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js
。因为我相信您正在使用引导版本3.x.x


请参阅更新jquery版本后的工作示例:

检查head标记中是否添加了引导css。 如果没有,则将其添加到html中的head标记中

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
    <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
    <link rel="stylesheet" type="text/css"   href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">


charly是的,我在JSFiddle中试用过,效果很好。我按照Jerad的建议更新了jquery.min.js,效果很好。谢谢。那么,与问题本身中的原始示例相比,有什么问题吗?你能详细说明一下吗?托比,对不起,你是对的。我编辑我的答案,所以!