Link to specific part of page

丶灬走出姿态 提交于 2020-04-06 08:47:13

问题


I've tried all of the following:

<a name="test"></a>
<a id="test"></a>
<h4 id="test">SOME TEXT</h4>

And then linking to them like this:

<a href="pagename#test">

All of the above work with Firefox, IE and Chrome, but none of them worked with Safari 5.xx on a mac. Any help is very much appreciated.


回答1:


<a href="#test">Go to Test</a>

. . .

<div id="test">This is Test.</div>

This should work.

EDITED: Also, if you want to link to a particular id in a different page, which I think you do, use:

<a href="somepage.html#test">Go to Test on some different page.</a>




回答2:


Looks like you have a misunderstanding of how anchors work, you need to use the href attribute.

<a name="test"></a>          <!-- not required -->
<a id="test"></a>            <!-- not required -->
<h4 id="test">SOME TEXT</h4> <!-- this is correct -->

To link to the <h4 id="test"> element do this (if target on the same page):

<a href="#test">Go to Test</a>

If target on a different page:

<a href="other_page.html#test">


来源:https://stackoverflow.com/questions/14423772/link-to-specific-part-of-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!