当前位置: 动力学知识库 > 问答 > 编程问答 >

jquery - Bootstrap w3school tutorial Dropdown not work

问题描述:

Hi I'm new with bootstrap and I'm trying to create the dropdown bootstrap and its not working.

Here is my HTML

<!DOCTYPE html>

<html>

<head>

<title>Sample</title>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>

<script type="text/javascript" src="js/bootstrap.min.js"></script>

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

</head>

<body>

<div class="dropdown">

<button class="btn btn-primary dropdown-toggle" type="button" id="ddButton" data-toggle="dropdown">Button</button>

<ul class="dropdown-menu" role="menu">

<li><a href="#">HTML</a></li>

<li><a href="#">CSS</a></li>

<li><a href="#">JavaScript</a></li>

</ul>

</div>

</body>

</html>

I'm using w3school.com as reference.

网友答案:

From the console:

bootstrap.min.js:6 Uncaught Error: Bootstrap's JavaScript requires jQuery version 1.9.1 or higher, but lower than version 4

Update jQuery

3.x snippet:

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

2.x snippet:

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

1.x snippet:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
网友答案:

Bootstrap's JavaScript requires jQuery version 1.9.1 or higher, but lower than version 4. your jquery version is 1.6.2 so update it to a recent one.

网友答案:

Add Script And Css In Your project . More Information Learn Boostrap DropDown W3schools Tutorial

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

See Example

<!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

 <div class="dropdown">
        <button class="btn btn-primary dropdown-toggle" type="button" id="ddButton" data-toggle="dropdown">Button</button>
        <ul class="dropdown-menu" role="menu">
              <li><a href="#">HTML</a></li>
              <li><a href="#">CSS</a></li>
              <li><a href="#">JavaScript</a></li>
        </ul>
   </div>
</body>
</html>
网友答案:

You missed to include the css for bootstrap. Try this. The path you have included might be wrong. Please verify that.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>

<body>

    <body>
        <div class="dropdown">
            <button class="btn btn-primary dropdown-toggle" type="button" id="ddButton" data-toggle="dropdown">Button</button>
            <ul class="dropdown-menu" role="menu">
                <li><a href="#">HTML</a></li>
                <li><a href="#">CSS</a></li>
                <li><a href="#">JavaScript</a></li>
            </ul>
        </div>
    </body>
</body>

</html>
分享给朋友:
您可能感兴趣的文章:
随机阅读: