如何从另一个加载一个JavaScript文件? [英] How to load one JavaScript file from another?
本文介绍了如何从另一个加载一个JavaScript文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从CSS等其他JavaScript文件加载一个JavaScript文件?
在CSS中我们使用write @import url(mycss.css);
。
How do you load one JavaScript file from another JavaScript file, like CSS?
In CSS we use write @import url("mycss.css");
.
Is有没有办法在JavaScript中做到这一点?
Is there any way to do it in JavaScript?
推荐答案
是的。如果你想要纯JavaScript,你必须动态创建一个脚本
标签,并将其附加到文件中。
Yes. If you want in pure JavaScript, you have to create dynamically a script
tag, and append it to the document.
是。如果使用jQuery库,则可以使用 $。getScript
方法。
Yes. If you use the jQuery library, you can use the $.getScript
method.
$.getScript("another_script.js");
这篇关于如何从另一个加载一个JavaScript文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文