jquery:如何将其他 .js 文件包含到 .js 中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2598469/
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-08-26 13:52:20  来源:igfitidea点击:

jquery: how to include other .js-files into .js

jqueryjquery-pluginsincludeexternal

提问by Heinrich

Is there any jquery plugin (instead of incldeMany) or simple function to include js-files on demand ?

是否有任何 jquery 插件(而不是 incldeMany)或简单的函数来按需包含 js 文件?

for example:

例如:

$.include('myscript.js'); 

?

?

回答by Olly Hodgson

How about jQuery.getScript()? It's built in to jQuery and works like so:

如何jQuery.getScript() ?它内置于 jQuery 中,工作原理如下:

$.getScript('ajax/test.js', function() {
    alert('Load was performed.');
});

回答by Aaron Wagner

Not exactly a jQuery plugin, but you might try looking into RequireJS. Especially the "How to use RequireJS with jQuery" section.

不完全是 jQuery 插件,但您可以尝试查看RequireJS。特别是“如何在 jQuery 中使用 RequireJS”部分。

I don't have much experience with this solution yet, but from what I've read and played around with I like the possibilities.

我对这个解决方案还没有太多经验,但从我读过和玩过的东西来看,我喜欢这些可能性。