如何将一个html页面链接到另一个文件夹中的另一个页面 [英] How to link one html page to another one in another folder

查看:261
本文介绍了如何将一个html页面链接到另一个文件夹中的另一个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法将页面"index2.html" 0从"rock-paper-scissors-game2"文件夹链接到"digital-clock"文件夹中的"index.html".不确定代码是否错误或其他原因.

Can't link the page "index2.html"0 from the "rock-paper-scissors-game2" folder to "index.html" in the "digital-clock" folder. Not sure if the code is wrong or something else.

顺便说一句,我正在使用Atom,但我不知道还要尝试什么,因为该链接的代码看起来正确.

I'm using Atom by the way, and I don't know what else to try because the code for the link looks correct.

<a href="rock-paper-scissors-game2/index2.html"> Game </a>

当我在chrome中运行它时,出现文件未找到错误.

And when I run it in chrome it gives the file not found error.

未找到您的文件,它可能已被移动或删除. ERR_FILE_NOT_FOUND

Your file was not found It may have been moved or deleted. ERR_FILE_NOT_FOUND

推荐答案

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

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.

这篇关于如何将一个html页面链接到另一个文件夹中的另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆