twitter-bootstrap 需要在 bootstrap.js 之后加载 bootstrap-dropdown.js 以使下拉列表工作 - 为什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17636149/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 17:35:51  来源:igfitidea点击:

Need to load bootstrap-dropdown.js after bootstrap.js to make dropdown work - why?

javascripttwitter-bootstrapdrop-down-menu

提问by Bryan Hanson

New to bootstrap and javascriptand was trying to build a fairly minimal example of a dropdown menu. I am using bootstrap 2.3.2which is the current version. My cssand jsare visible in my IDE. From the bootstrapdocs it seems that a standard install of bootstrap.jscontains bootstrap-dropdown.jsand I can see it in the file. Yet, I need to have the following for the drop down menu to work:

bootstrap 的新手,javascript并试图构建一个相当小的下拉菜单示例。我正在使用bootstrap 2.3.2哪个是当前版本。我的cssjs在我的 IDE 中可见。从bootstrap文档看来,标准安装bootstrap.js包含bootstrap-dropdown.js,我可以在文件中看到它。但是,我需要以下内容才能使下拉菜单正常工作:

<script src="http://code.jquery.com/jquery.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<script src="assets/js/bootstrap.js"></script>
<script src="http://twitter.github.com/bootstrap/assets/js/bootstrap-dropdown.js"></script>

Why do I have to load bootstrap-dropdown.jsseparately if it is included in bootstrap.js? Obviously there is something fundamental here that I don't understand. Thanks.

bootstrap-dropdown.js如果包含在 中,为什么我必须单独加载bootstrap.js?显然,这里有一些我不明白的基本原理。谢谢。

回答by The Alpha

From Bootstrap website :

从 Bootstrap 网站:

Plugins can be included individually (though some have required dependencies), or all at once. Both bootstrap.js and bootstrap.min.js contain all plugins in a single file.

插件可以单独包含(尽管有些插件需要依赖项),也可以同时包含所有插件。bootstrap.js 和 bootstrap.min.js 都在一个文件中包含所有插件。

Both bootstrap.jsand bootstrap.min.jscontain all plugins in a single file. you do not need the bootstrap-dropdown.jsif you include bootstrap.min.jsor bootstrap.jsfrom the bootstrap page, check this overview on Bootstrap site. i can see that you are including both bootstrap.min.jsand bootstrap.jsbut only one is enough. Check the demo here, only using bootstrap.js.

双方bootstrap.jsbootstrap.min.js包含在一个单一文件中的所有插件。bootstrap-dropdown.js如果您包含bootstrap.min.jsbootstrap.js引导程序页面,您不需要,请在引导程序站点上查看此概述。我可以看到您同时包含了两者bootstrap.min.jsbootstrap.js但只有一个就足够了。 在此处查看演示,仅使用bootstrap.js.

Also, you can download a customized version from here, just according to your need you can add components/plugins and then download the custom build.

另外,您可以从这里下载定制版本,根据您的需要,您可以添加组件/插件,然后下载定制版本。