导航到另一个页面上的锚点 [英] Navigate to an anchor on another page

查看:47
本文介绍了导航到另一个页面上的锚点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想从一个页面导航到另一个页面的特定点.

I simply want to navigate from one page to a specific point on another.

我有一个包含四个部分的主页:

I have a home page with four sections:

<section>
   <a name="section1"></a>
</section>

<section id="section2">

</section>

<section>
   <a name="section3"></a>
</section>

<section id="section4">

</section>

每个页面上都有第 2 节和第 4 节,所以我的导航看起来像:

Section 2 and 4 feature on every page, so my nav looks like:

<nav>
    <ul>
        <li><a href="index.html#section1">ABOUT</a></li>
        <li><a href="#section2">APARTMENTS</a></li>
        <li><a href="index.html#section3">LANDLORDS</a></li>
        <li><a href="#section4">CONTACT</a></li>
    </ul>
</nav>

链接未导航到索引页或索引页的所需部分.

The links aren't navigating to the index page or the desired section of the index page.

现在我有:

<section>
       <a name="section1"></a>
</section>

<section id="section2">

</section>

<section>
   <a name="section3"></a>
</section>

<section id="section4">

</section>

还有我的导航:

<nav>
    <ul>
        <li><a href="#section1">ABOUT</a></li>
        <li><a href="#section2">APARTMENTS</a></li>
        <li><a href="#section3">LANDLORDS</a></li>
        <li><a href="#section4">CONTACT</a></li>
    </ul>
</nav>

它仍然无法正常工作.

推荐答案

您确定将文件放在同一目录中吗?我已经测试了您提供的代码并且可以正常工作.但是,您可以尝试一下(一种为部分指定 ID 的不同方式):

Are you sure that you have placed the files in the same directory? I've tested the code that you have provided and it's working. However, you could try this out (a different way of giving sections an id):

<section>
    <a id="section1">
        CONTENT
    </a>
</section>

如果您已经这样做了,只需使用相同的链接方式:

If you have done this, just use the same way of linking:

<a href="different-page.html#section1">Section One</a>

这篇关于导航到另一个页面上的锚点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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