JavaScript导航到命名超链接

时间:2011-11-24 13:55:54

标签: javascript html hyperlink

我有以下超链接:

<a name="top"></a>

我的按钮如下所示:

<span id="listControl_1_ctl15" onclick="window.location='#top'" class="TextButton">
    <span class="button_left"></span>
    <span class="button_text">Bovenaan</span>
    <span class="button_right"></span>
</span>

我的页面未导航到顶部。有谁知道为什么?

3 个答案:

答案 0 :(得分:4)

把它放在你称之为顶部的地方:

<a name="top"></a> 

然后您可以使用它来转到链接

<a href= "#top"> go to the top </a>

如果你想要转到整个页面的顶部,你也可以使用它:

<a href = #> TOP! </a>

的Stefan。

答案 1 :(得分:3)

使用window.location.hash

<span id="listControl_1_ctl15" onclick="window.location.hash='top'" class="TextButton">
    <span class="button_left"></span>
    <span class="button_text">Bovenaan</span>
    <span class="button_right"></span>
</span>

答案 2 :(得分:2)

你应该使用hash:

window.location.hash='top'