如何在另一个 javascript 文件中包含 jquery

2022-01-25 00:00:00 include jquery javascript

我有一个 javascript 文件,我想在这个 js 文件中包含 jquery.你有什么建议吗?

I have a javascript file and I want to include jquery in this js file. Do you have a suggestion?

推荐答案

在包含您自己的 JavaScript 之前,只需包含 jQuery 的 JavaScript:

Simply include the JavaScript for jQuery before you include your own JavaScript:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script src="path/to/your/script.js"></script>

虽然其他人建议简单地将 jQuery 复制并粘贴到您自己的 JavaScript 文件中,但最好将 jQuery 与规范源分开包含,因为这将允许您利用浏览器和中间服务器为此所做的缓存文件.

Though others have suggested simply copying and pasting jQuery into your own JavaScript file, it's really better to include jQuery separately from a canonical source as that will allow you to take advantage of the caching that your browser and intermediate servers have done for that file.

相关文章