3

如果我像这样设置我的基本网址:

<base href='http://example.com' />

然后在http://example.com/test.php页面上放置一个指向锚点的链接:

<a href='#top'></a>

我如何确保锚点保持在同一页面上并转到链接http://example.com/test.php#top而不是转到http://example.com/#top因为它使用基础网址?

本质上,有没有办法指定这个特定的链接必须是相对的而不是使用基础?

4

1 回答 1

2

你可以这样做:

<base href='http://example.com' />
<a href='test.php#top'></a>

或者

<base href='http://example.com/test.php' />
<a href='#top'></a>

如果您不定义它,我认为客户端不会有任何神奇的方式知道将哪个文件用作基础的一部分。

于 2011-11-16T14:33:47.137 回答