Javascript src 中的路径以到达不同目录中的文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8889354/
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
Path in src to reach a file in a different directory
提问by Oni Enzeru
I have a folder called projects
and in it I have a game
folder and an engine
folder. I have my engine.js
file inside the engine
folder and I was wondering if I could access it with my game.html
file from the other folder like so
我有一个名为的文件夹projects
,其中有一个game
文件夹和一个engine
文件夹。我的engine.js
文件在engine
文件夹中,我想知道是否可以game.html
像这样使用其他文件夹中的文件访问它
<script type ="text/javascript" src ="\engine/engine.js"/>
Now, obviously the above doesn't work, but what I need to do is go back out of the game
folder to the project
folder and then into the engine
folder.
现在,显然上述方法不起作用,但我需要做的是从game
文件夹返回到project
文件夹,然后再进入engine
文件夹。
File tree: projects folder
文件树:项目文件夹
- projects
- engine
- engine.js
- game
- game.js
- engine
- 项目
- 引擎
- 引擎.js
- 游戏
- 游戏.js
- 引擎
What is the proper format for src
to provide users with a link to engine.js
?
src
为用户提供链接的正确格式是什么engine.js
?
回答by njbair
Use a double-dot to go back:
使用双点返回:
src="../engine/engine.js"
src="../engine/engine.js"
回答by vdbuilder
That would be:
那将是:
<script type ="text/javascript" src ="../engine/engine.js"/>