我有一个经常会被发现的问题。问题在于,没有任何地方可以找到一个明确的解决方案。
关于锚,我有两个问题。
主要目标应该是得到一个漂亮的干净的网址,没有任何散列在它同时使用锚跳转到一个页面。
所以锚的结构是:
<ul>
<li><a href="#one">One</a></li>
<li><a href="#two">Two</a></li>
<li><a href="#three">Three</a></li>
</ul>
<div class="wrap">
<a name="one">text 1</a>
<a name="two">text 2</a>
<a name="three" class="box">text 3</a>
</div>
好的,如果你点击其中一个链接,网址会自动变成
Www.domain.com/page#1
最终,这应该是公正的:
Www.domain.com/page
目前为止,一切顺利。现在的第二件事情是,当你搜索互联网上的问题,你会发现 javascript
作为一个解决方案。
我发现了这个函数:
function jumpto(anchor){
window.location.href = "#"+anchor;
}
并调用该函数:
<a onclick="jumpto('one');">One</a>
什么将是相同的像以前。它将添加散列到网址。我还添加了
<a onclick="jumpto('one'); return false;">
所以如果有人能告诉我如何解决这个问题,我会非常感激。
非常感谢。