在另一个js文件中加载外部js文件

Gau*_*rav 24 javascript jquery

我有这个文件包含在我的HTML中,我想从另一个JavaScript调用它.请建议我该怎么办?

<script type="text/javascript" src="js.js">/*
  old:123
  new: 456*/
</script>
Run Code Online (Sandbox Code Playgroud)

我想将它包含在我的js文件中,而不是在html中.

doi*_*tin 61

如果你想在你可以使用一个JS JS文件jQuery.getScript()

$.getScript('another_file.js', function() {
    //script is loaded and executed put your dependent JS here
});
Run Code Online (Sandbox Code Playgroud)

如果你不能使用jQuery

var imported = document.createElement('script');
imported.src = '/path/to/imported/script';
document.head.appendChild(imported);
Run Code Online (Sandbox Code Playgroud)

资源