且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将一个html页面链接到另一个文件夹中的另一个页面

更新时间:2023-01-07 15:28:03

要在网站结构内链接到另一个文件,应使用

To link to another file WITHIN your web site structure, you should use relative references. Relative means, relative to the currently loaded resource.

要访问同一文件夹中的内容:只需使用文件名:

To access something in the same folder: Just use the file name:

<a href="file.html">Click Me<a>

要访问子文件夹中的内容:以子文件夹名称,斜杠和文件名开头:

To access something in a child folder: Start with the child folder name, a slash, and the file name:

<a href="childFolder/file.html">Click Me<a>

要访问从网站根目录开始的内容,请以正斜杠开头:

To access something starting at the root of your site, begin the path with a forward-slash:

<a href="/pathToFile">Click Me<a>

要访问父文件夹中的内容,请以两个点和一个正斜杠开头:

To access something in a parent folder, start with two dots and a forward-slash:

<a href="../file.html">Click Me<a>

要访问以上各项的组合(例如兄弟文件夹),您需要上级到父级,然后下到正确的子级:

To access something that is in a combination of the above, like a sibling folder, you need to go up to the parent and then down to the correct child:

<a href="../digital-clock/index2.html">Click Me<a>

作为确保该文件存在的初步测试,请暂时将其放置在与当前页面相同的文件夹中,并查看我显示的第一个示例是否可行.如果没有,那么您遇到的问题与您想象的不同.

As an initial test to make sure the file exists, temporarially place it in the same folder as the current page and see if the first example I showed works. If not, you've got a different issue than you think.

接下来,您提到index2.htmldigital-clock文件夹中,但是您没有在链接中引用该文件夹,因此请确保将其包括在内.但是,取决于该文件夹的位置,将决定您需要使用上面显示的哪种方法.

Next, you mention that index2.html is in the digital-clock folder, but you didn't reference that folder in your link, so make sure to include that. But, depending on where that folder is will dictate which method I've shown above you need to use.