如何添加指向“目录树上方两级”的超链接?
我正在尝试编写我的主页按钮。有没有办法只爬回文件结构,而不是像我下面那样使用绝对路径。
我有一个文件index.html,位于 C:\Users\Randy\Documents\XML\
这是我的代码:
<a id="my-family" href="C:\Users\Randy\Documents\XML\index.html">Home</a>
这是我试图来自的地方:C:\Users\兰迪\文档\XML\项目\xml
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
要上两级,请使用“../../”和两级文件夹中的普通网址。
路径中的“../”用于向上一级。但是,它可以使用更多次,提升更多级别。
示例:
myfile.html 包含:
第二个“../”从 PICTURE_CONFIG 到 CONFIG 文件夹
第一个“../”从 CONFIG 转到 HOME 文件夹
“image.jpg”在 HOME 文件夹中搜索文件“image.jpg”
to go two level up use "../../" and your normal url from two level up folder.
"../" in the path is used to go one level up. But, it can be used for more times, to go more levels up.
an example:
myfile.html contains:
the second"../" goes from PICTURE_CONFIG to CONFIG folder
the first "../"goes from CONFIG to HOME folder
"image.jpg" searches in HOME folder for the file "image.jpg"
您可以使用
../index.html
来引用父目录中的index.html
。You can use
../index.html
to refer toindex.html
in the parent directory.在 Windows 操作系统上,正斜杠 (/) 不起作用,因此我切换到反斜杠 (\) 并修复了该问题。例如,尝试使用以下内容:
On Windows OS, the forward-slash (/) wasn't working, so I switched to back-slash (\) and that fixed it. For example, try using the following:
我不确定你到底在问什么,但在相对路径中,
../
是“上一级”。因此,
../index.html
会将您带到下一个目录的索引。希望有帮助。I'm not sure exactly what you're asking, but in relative paths,
../
is 'up one level'.So,
../index.html
would take you to the index of the next directory up. Hope that helps.当 picture.jpg 与当前页面位于同一文件夹中时
何时picture.jpg 位于当前文件夹的 images 文件夹中
当 picture.jpg 位于当前网站根目录的 images 文件夹中时
当 picture.jpg 位于当前文件夹的上一级文件夹时
当 picture.jpg 位于当前文件夹上两级的文件夹中时
希望此示例有所帮助:)
来源:https://www.w3schools.com/html/html_filepaths.asp
<img src="picture.jpg">
WHEN picture.jpg is located in the same folder as the current page<img src="images/picture.jpg">
WHEN picture.jpg is located in the images folder located in the current folder<img src="/images/picture.jpg">
WHEN picture.jpg is located in the images folder located at the root of the current web<img src="../picture.jpg">
WHEN picture.jpg is located in the folder one level up from the current folder<img src="../../picture.jpg">
WHEN picture.jpg is located in the folder two levels up from the current folderHope this example help :)
Source: https://www.w3schools.com/html/html_filepaths.asp
在 IIS10 中,下面是我的观察结果,两者都工作正常:
单个点将带您上面一个文件夹
img src="./images/picture.jpg"
双点将带您上面的两个文件夹
img src="../images/picture.jpg"
In IIS10 below is my observation and both works fine:
single Dot will take you one folder above
img src="./images/picture.jpg"
Double Dot will take you two folders above
img src="../images/picture.jpg"