简体   繁体   English

将Javascript文件包含在另一个javascript文件中并加载

[英]Include Javascript file in another javascript file and Loading

I trying to make one path.js file by which all js files in different folders get paths from. 我试图制作一个path.js文件,通过该文件,不同文件夹中的所有js文件都可以从中获取路径。 Obiviosuly I am making a big blunders in my code so how can i do that. 不好意思我在我的代码中犯了一个大错误,所以我该怎么做呢。

For Example the folder structure is like this: 例如,文件夹结构如下:

ProjectFolder
-- index.html
-- paths.js
-- newFolder
     -- main.js
     -- main1.js

Here is my code: 这是我的代码:

index.html 的index.html

<html>
<head>
   <script type="text/javascript" src="main/main.js"></script>
   <script>
      alert(dis);
   </script>    
</head>
<body>
</body>
</html>

main.js main.js

<script type="text/javascript" src="../path.js"> </script>
var dis = path;

paths.js paths.js

var path = "PATH";
var path2 = "PATH2";

Just include paths.js in your html.file.as a link. 只需在你的html.file.as链接中包含paths.js。 The other js files will then see it's variables. 然后其他js文件将看到它的变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM