事实证明,引用本地资源可能是一些人的一个问题。我正在寻找本地资源引用的规范答案,以及它们的含义。
举几个例子,这些参考路径有什么区别?
<img src="myfile.png" />
(无前导斜线)<img src="/myfile.png" />
(带斜杠)<img src="folder/myfile.png" />
(子文件夹中没有前导斜杠)<img src="/folder/myfile.png" />
(带有斜杠/子文件夹)<img src="../folder/myfile.png" />
(带点和前导斜杠/在子文件夹中)答案 0 :(得分:104)
采用以下文件夹结构
通知:
现在在index.html.en
文件中,您需要添加以下标记
<p>
<span>src="check_mark.png"</span>
<img src="check_mark.png" />
<span>I'm purple because I'm referenced from this current directory</span>
</p>
<p>
<span>src="/check_mark.png"</span>
<img src="/check_mark.png" />
<span>I'm green because I'm referenced from the ROOT directory</span>
</p>
<p>
<span>src="subfolder/check_mark.png"</span>
<img src="subfolder/check_mark.png" />
<span>I'm yellow because I'm referenced from the child of this current directory</span>
</p>
<p>
<span>src="/subfolder/check_mark.png"</span>
<img src="/subfolder/check_mark.png" />
<span>I'm orange because I'm referenced from the child of the ROOT directory</span>
</p>
<p>
<span>src="../subfolder/check_mark.png"</span>
<img src="../subfolder/check_mark.png" />
<span>I'm purple because I'm referenced from the parent of this current directory</span>
</p>
<p>
<span>src="subfolder/subfolder/check_mark.png"</span>
<img src="subfolder/subfolder/check_mark.png" />
<span>I'm [broken] because there is no subfolder two children down from this current directory</span>
</p>
<p>
<span>src="/subfolder/subfolder/check_mark.png"</span>
<img src="/subfolder/subfolder/check_mark.png" />
<span>I'm purple because I'm referenced two children down from the ROOT directory</span>
</p>
现在,如果您加载位于第二个子文件夹中的index.html.en
文件
http://example.com/subfolder/subfolder/
这将是您的输出