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

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

问题描述

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

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 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天全站免登陆