通过另一个js文件动态加载js文件? [英] loading js files dynamically via another js file?

查看:128
本文介绍了通过另一个js文件动态加载js文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论如何都要在单个JS文件中加载其他JS文件。我想指出我的单个页面ITSjs文件和js文件将加载jquery,其他js文件。

is there anyway to load other JS files from within a single JS file. I would like to point my individual pages "ITS" js file and that js file would load jquery, other js files.

我知道我可以将所有这些都弹出到html即

我在考虑关注点的分离,所以我想知道是否有任何事情存在,如果没有我重新发明轮子....

I know i can just pop all these into the html i.e.

I was thinking of separations of concerns so i was wondering if anything exists already without me reinventing the wheel....

我只需要编辑home.js来改变为home.htm加载的其他js(jquery等)... home.htm只会指向home.js

That i would just need to edit home.js to change what other js (jquery etc) are loaded for home.htm ... home.htm would just point to home.js

谢谢

推荐答案

你可以看看动态脚本加载。以下是文章的摘录:

You can take a look at dynamic script loading. Here's an excerpt from the article:

var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'helper.js';
head.appendChild(script);

这篇关于通过另一个js文件动态加载js文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆