简体   繁体   English

Bootstrap v4下拉菜单不起作用

[英]Bootstrap v4 Dropdown menu not working

Idk why but I'm using bootstrap v4 and the drop down menu, literally copy and pasted from the documentation, doesn't work. 不知道为什么,但是我正在使用bootstrap v4,从菜单上直接复制和粘贴的下拉菜单不起作用。 I've also tried other peoples examples on blank pages. 我还在空白页面上尝试了其他人的示例。 Nothing. 没有。

 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet"/> <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script> <div class="col-12"> <div class="dropdown"> <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> Dropdown button </button> <div class="dropdown-menu" aria-labelledby="dropdownMenuButton"> <a class="dropdown-item" href="#">Action</a> <a class="dropdown-item" href="#">Another action</a> <a class="dropdown-item" href="#">Something else here</a> </div> </div> </div> 

Assuming you have indeed downloaded and referenced the files correctly, your code above will work as expected. 假设您确实已正确下载并引用了文件,则上面的代码将按预期工作。 Note that you have referenced your files relatively , so they must be in a scripts folder at the same level as the file you are trying to run Bootstrap on. 请注意,您已经相对地引用了文件,因此它们必须与要在其上运行Bootstrap的文件位于同一级别的scripts文件夹中。

The only required files are jQuery, Tether and Bootstrap.js. 唯一需要的文件是jQuery,Tether和Bootstrap.js。 popper.js is unnecessary. popper.js是不必要的。 In addition to the three required JavaScript files, you'll also probably want the Boostrap CSS file as well. 除了三个必需的JavaScript文件之外,您可能还需要Boostrap CSS文件。

The JavaScript files should be referenced in the following order: 应按以下顺序引用JavaScript文件:

  1. jQuery jQuery的
  2. Tether 系链
  3. Bootstrap's JavaScript component Bootstrap的JavaScript组件

It doesn't matter when you load Bootstrap's CSS. 加载Bootstrap的CSS无关紧要。

This can be seen working in the following example: 在以下示例中可以看到它的工作原理:

 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous"> <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script> <div class="col-12"> <div class="dropdown"> <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> Dropdown button </button> <div class="dropdown-menu" aria-labelledby="dropdownMenuButton"> <a class="dropdown-item" href="#">Action</a> <a class="dropdown-item" href="#">Another action</a> <a class="dropdown-item" href="#">Something else here</a> </div> </div> </div> 

Feel free to build from this template. 随意从此模板进行构建。

Hope this helps! 希望这可以帮助! :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM