正确加载命令jQuery,Bootstrap和select2 .js文件(Correct loading order jQuery, Bootstrap and select2 .js files)

我想问一下,在你的网页中是否有一个特定的加载顺序应该用于jQuery,Bootstrap和Select2 JavaScript文件,以避免任何潜在的错误,以及是否应该有一个最合适的加载顺序。

I would like to ask if there is a specific loading order in your web pages that should be used for the jQuery, Bootstrap and Select2 JavaScript files in order to avoid any potential errors and if there should be one what would be the most appropriate one.

最满意答案

您将始终需要 bootstrap 之前加载jQuery或依赖它的任何其他插件。

我喜欢首先将我的链接/引用命名为JavaScript,然后确保每个引用都是按各自的插件排序的,但这只是我个人的偏好。

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

You will always need to load jQuery before bootstrap or any other plugins that rely on it.

I like to order my links/references as JavaScript first, css second and ensure that each reference is ordered by their respective plugin but thats just my own personal preference.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.5/js/select2.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.5/css/select2.min.css" rel="stylesheet"/>正确加载命令jQuery,Bootstrap和select2 .js文件(Correct loading order jQuery, Bootstrap and select2 .js files)

我想问一下,在你的网页中是否有一个特定的加载顺序应该用于jQuery,Bootstrap和Select2 JavaScript文件,以避免任何潜在的错误,以及是否应该有一个最合适的加载顺序。

I would like to ask if there is a specific loading order in your web pages that should be used for the jQuery, Bootstrap and Select2 JavaScript files in order to avoid any potential errors and if there should be one what would be the most appropriate one.

最满意答案

您将始终需要 bootstrap 之前加载jQuery或依赖它的任何其他插件。

我喜欢首先将我的链接/引用命名为JavaScript,然后确保每个引用都是按各自的插件排序的,但这只是我个人的偏好。

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

You will always need to load jQuery before bootstrap or any other plugins that rely on it.

I like to order my links/references as JavaScript first, css second and ensure that each reference is ordered by their respective plugin but thats just my own personal preference.

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