如何链接相同或不同文件夹中的html页面?

发布于 2024-07-22 04:43:08 字数 48 浏览 1 评论 0原文

如果 html 页面位于相同或不同的文件夹中,而无需编写完整路径,如何链接到它们?

How can I link to html pages if they are in same or different folders without writing full path?

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

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

发布评论

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

评论(14

伏妖词 2024-07-29 04:43:08

在同一文件夹中,只需使用文件名:

<a href="thefile.html">my link</a>

在父文件夹的目录中:

<a href="../thefile.html">my link</a>

在子目录中:

<a href="subdir/thefile.html">my link</a>

Within the same folder, just use the file name:

<a href="thefile.html">my link</a>

Within the parent folder's directory:

<a href="../thefile.html">my link</a>

Within a sub-directory:

<a href="subdir/thefile.html">my link</a>
眼眸印温柔 2024-07-29 04:43:08

此外,这将进入一个目录,然后返回到另一个子文件夹。

<a href = "../subfolder/page.html">link</a>

要进入多个目录,您可以这样做。

<a href = "../../page.html">link</a>

为了追根溯源,我用这个

<a href = "~/page.html">link</a>

Also, this will go up a directory and then back down to another subfolder.

<a href = "../subfolder/page.html">link</a>

To go up multiple directories you can do this.

<a href = "../../page.html">link</a>

To go the root, I use this

<a href = "~/page.html">link</a>
烟柳画桥 2024-07-29 04:43:08

另外,如果要引用根目录,可以使用:

/

which willrefer to root。 因此,假设我们所在的文件嵌套在几层文件夹中,并且您想要返回主index.html:

<a href="/index.html">My Index Page</a>

Robert 提供了进一步的相对路径解释。

In addition, if you want to refer to the root directory, you can use:

/

Which will refer to the root. So, let's say we're in a file that's nested within a few levels of folders and you want to go back to the main index.html:

<a href="/index.html">My Index Page</a>

Robert is spot-on with further relative path explanations.

清风无影 2024-07-29 04:43:08

在层次结构中向上移动一个文件夹,您的链接将如下所示:

../

您可以使用So 从 /webroot/site/pages/folder1/myotherpage.htm 访问文件夹 /webroot/site/pages/folder2/mypage.htm ,

<a href="../folder2/mypage.htm">Link to My Page</a>

You can go up a folder in the hierarchy by using

../

So to get to folder /webroot/site/pages/folder2/mypage.htm from /webroot/site/pages/folder1/myotherpage.htm your link would look like this:

<a href="../folder2/mypage.htm">Link to My Page</a>
热血少△年 2024-07-29 04:43:08

使用相对路径

主页可能是:
/index.html

二级页面:
/otherFolder/otherpage.html

链接如下所示:

<a href="/otherFolder/otherpage.html">otherpage</a>

use the relative path

main page might be:
/index.html

secondary page:
/otherFolder/otherpage.html

link would be like so:

<a href="/otherFolder/otherpage.html">otherpage</a>
晚雾 2024-07-29 04:43:08

如果您想链接到根目录,可以使用

//index.html

如果您想链接到同一目录中的文件,只需输入文件名

<a href="/employees.html">Employees Click Here</a>

要移回文件夹,您可以使用

../

要从根目录链接到员工目录中的索引页面,您可以这样做

<a href="../employees/index.html">Employees Directory Index Page</a>

If you'd like to link to the root directory you can use

/, or /index.html

If you'd like to link to a file in the same directory, simply put the file name

<a href="/employees.html">Employees Click Here</a>

To move back a folder, you can use

../

To link to the index page in the employees directory from the root directory, you'd do this

<a href="../employees/index.html">Employees Directory Index Page</a>
强辩 2024-07-29 04:43:08

我要提醒您:如果您使用绝对路径,那么您的应用程序不能安装在服务器的“子目录”中!

例如, http://yourserver.com/yourapp 可能有效,但 http://myserver.com/apps/yourapp 不会!

I would caution you: if you are using absolute paths, then your application cannot be installed in a "subdirectory" of the server!

eg, http://yourserver.com/yourapp may work, but http://myserver.com/apps/yourapp will not!

°如果伤别离去 2024-07-29 04:43:08

简短回答:

. 表示当前目录

.. 表示上层目录,如 shell 上的 cd .. 命令。

简单但棘手,我写这个答案主要是为了自己下次不要忘记。

ademSite/
├── index.html
└── style.css

index.htmlCSS 的链接:


ademSite/
├── index.html
└── stylefiles
    └── style.css

这种情况应该是:

├── html
│   └── index.html
└── stylefiles
    └── style.css

在这种情况下,路径必须 是:

Short answer:

. is for current directory

.. is for upper directory as in cd .. command on shell.

Simple yet tricky, I write this answer primarily for myself not to forget next time.

ademSite/
├── index.html
└── style.css

The link to CSS in index.html:

<link rel="stylesheet" href="style.css"> or
<link rel="stylesheet" href="./style.css">

ademSite/
├── index.html
└── stylefiles
    └── style.css

This case it should be:

<link rel="stylesheet" href="stylefiles/style.css"> or <link rel="stylesheet" href="./stylefiles/style.css">

├── html
│   └── index.html
└── stylefiles
    └── style.css

In this case path must be:
<link rel="stylesheet" href="../stylefiles/style.css">

岁吢 2024-07-29 04:43:08

例如

../

,如果您的文件位于 folder2folder1
你这样找到它

../folder1/folder2/image

Use

../

For example if your file, lets say image is in folder1 in folder2
you locate it this way

../folder1/folder2/image
池予 2024-07-29 04:43:08

href="./page.htm" 为同一目录

href="../page.htm" 父目录

href="~/page.htm" 根目录或最上层目录。

href="./page.htm" for the same directory

href="../page.htm" parent directory

href="~/page.htm" root directory or the upper most dir.

瞳孔里扚悲伤 2024-07-29 04:43:08

下面的答案是我创建的,用于将另一个共享驱动器中的 html 内容链接到我要发送给经理的 html 页面。 当然,路径与您的使用相关,但就我而言,我只会向他们发送 html,并且从加载运行程序动态更新的所有其他内容都会为我更新。
节省了大量的纸张,而且他们可以根据自己的需要使用这些数字,而不仅仅是用这种方式打印硬拷贝。

SRC="file://///shareddrive/shareddrive-folder/username/scripting/testReport\contents.html" NAME="contents_frame" title="Table of Contents"

Answer below is what I created to link html contents from another shared drive to the html page I would send out to managers. Of course, the path is relative to your using, but in my case, I would just send them the html, and everything else that is updated from load runner dynamically would be updated for me.
Saves tons of paper, and they can play with the numbers as they see fit instead of just a hard copy this way.

SRC="file://///shareddrive/shareddrive-folder/username/scripting/testReport\contents.html" NAME="contents_frame" title="Table of Contents"
傲鸠 2024-07-29 04:43:08

对于 ASP.NET,这对我的开发和部署很有用:

<a runat="server" href="~/Subfolder/TargetPage">TargetPage</a>

使用 runat="server"href="~/" 是转到根目录的关键。

For ASP.NET, this worked for me on development and deployment:

<a runat="server" href="~/Subfolder/TargetPage">TargetPage</a>

Using runat="server" and the href="~/" are the keys for going to the root.

冷月断魂刀 2024-07-29 04:43:08

这对我来说被点击

This worked for me <a href="preferedfile name.html">to be clicked <a/>

云裳 2024-07-29 04:43:08

当我创建网页时,我发现将 Html 文件移动到不同的文件夹时,它会更改图像、视频、音乐、PDF 文件等的路径。使用它们,您必须走出 HTML 所在的文件位于,与
<代码>../HTML。 然后,当您退出时,根据页面内容的位置,插入,

 <a href="Meme/WP/Chipmunk.html">Chipmunk Memes</a>
 
 */ This is where the HTML is located ^^^^^^ */
 
 <img class="demo cursor" src="../6.png" width="100" height="50" onclick="currentSlide(6)" alt="Sasha Having Some Fun">
 
 */ This is where the images are located. The "../6.png" is the image file, and it is located one directory back. */

When I Was creating a webpage, I found out that With moving Html files to different Folders, It changes the paths of the images, videos, music, PDF files, etc. With them, you have to go out of the file the HTML is located in, with the
../HTML. Then when your out, depending on where your page content is, insert,

 <a href="Meme/WP/Chipmunk.html">Chipmunk Memes</a>
 
 */ This is where the HTML is located ^^^^^^ */
 
 <img class="demo cursor" src="../6.png" width="100" height="50" onclick="currentSlide(6)" alt="Sasha Having Some Fun">
 
 */ This is where the images are located. The "../6.png" is the image file, and it is located one directory back. */

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