Path in src to reach a file in a different directory

那年仲夏 提交于 2019-12-20 10:24:34

问题


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

 <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.

File tree: projects folder

  • projects
    • engine
      • engine.js
    • game
      • game.js

What is the proper format for src to provide users with a link to engine.js?


回答1:


Use a double-dot to go back:

src="../engine/engine.js"




回答2:


That would be:

<script type ="text/javascript" src ="../engine/engine.js"/>


来源:https://stackoverflow.com/questions/8889354/path-in-src-to-reach-a-file-in-a-different-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!