如何添加指向“目录树上方两级”的超链接?

发布于 2024-11-29 16:47:06 字数 308 浏览 1 评论 0 原文

我正在尝试编写我的主页按钮。有没有办法只爬回文件结构,而不是像我下面那样使用绝对路径。

我有一个文件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

I am trying to code my Home button. Is there a way to just climb back up the file structure, instead of using the absolute path like I have below.

I have a file index.html that I have at C:\Users\Randy\Documents\XML\

Heres my code:

<a id="my-family" href="C:\Users\Randy\Documents\XML\index.html">Home</a> 

Heres where I am trying to come from: C:\Users\Randy\Documents\XML\project\xml

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

眸中客 2024-12-06 16:47:06

要上两级,请使用“../../”和两级文件夹中的普通网址。

路径中的“../”用于向上一级。但是,它可以使用更多次,提升更多级别。

示例:

| HOME <br> 
+- image.jpg<br> 
|_
  |
  +- CONFIG<br>  
     |
     + PICTURE_CONFIG
       | 
       +- myfile.html

myfile.html 包含:

<img src="../../image.jpg" />

第二个“../”从 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:

| HOME <br> 
+- image.jpg<br> 
|_
  |
  +- CONFIG<br>  
     |
     + PICTURE_CONFIG
       | 
       +- myfile.html

myfile.html contains:

<img src="../../image.jpg" />

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"

·深蓝 2024-12-06 16:47:06

您可以使用../index.html来引用父目录中的index.html

You can use ../index.html to refer to index.html in the parent directory.

蘸点软妹酱 2024-12-06 16:47:06

在 Windows 操作系统上,正斜杠 (/) 不起作用,因此我切换到反斜杠 (\) 并修复了该问题。例如,尝试使用以下内容:

"..\..\index.html"

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"
浪菊怪哟 2024-12-06 16:47:06

我不确定你到底在问什么,但在相对路径中, ../ 是“上一级”。

因此, ../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.

兰花执着 2024-12-06 16:47:06
  1. 当 picture.jpg 与当前页面位于同一文件夹中时

  2. 何时picture.jpg 位于当前文件夹的 images 文件夹中

  3. 当 picture.jpg 位于当前网站根目录的 images 文件夹中时

  4. 当 picture.jpg 位于当前文件夹的上一级文件夹时

  5. 当 picture.jpg 位于当前文件夹上两级的文件夹中时

希望此示例有所帮助:)

来源:https://www.w3schools.com/html/html_filepaths.asp

  1. <img src="picture.jpg"> WHEN picture.jpg is located in the same folder as the current page

  2. <img src="images/picture.jpg"> WHEN picture.jpg is located in the images folder located in the current folder

  3. <img src="/images/picture.jpg"> WHEN picture.jpg is located in the images folder located at the root of the current web

  4. <img src="../picture.jpg"> WHEN picture.jpg is located in the folder one level up from the current folder

    1. <img src="../../picture.jpg"> WHEN picture.jpg is located in the folder two levels up from the current folder

Hope this example help :)

Source: https://www.w3schools.com/html/html_filepaths.asp

错々过的事 2024-12-06 16:47:06

在 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"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文