2011-10-08 62 views

回答

5

我建议你再哈希第一个测试移动用户的浏览器集中另一个元素之前:

if (!document.location.hash){ 
    document.location.hash = 'hi'; 
} 

JS Fiddle demo

顺便说一句,你可以使用哈希(在URL中#后的部分)跳转到具有id任何元素,你并不需要使用命名锚(<a name="hi">...</a>)。

+0

非常感谢JS Fiddle演示。 – user677900

+0

你很受欢迎;我很高兴得到了帮助! –

+0

什么时候我必须跳到Elemet上课? – user677900

1

您可以使用jQuery及其scrollTo插件一起,然后写些这样的:

$.scrollTo("a[name = hi]"); 

这应该只是罚款。

+1

-1,noone询问有关jquery的任何事情。 –

+2

+1,与问题仍然相关。用户没有得到实现他的目标的首选方式,他只是要求选择。 – Phillip

3

要么,你可以使用带有锚(mysite.com/#hi)的URL,或者你可以使用JavaScript:

document.getElementById('hi').scrollIntoView(true); 

请注意,您应该使用ID,没有名字。

1

我认为这将是有益的与锚的工作:

<a name="hi">here goes the text information what you like</a> 

创建同一文档内的链接,“喜科”:

<a href="#hi">Go to hi</a> 

或者,创建一个链接“hi Section”from other page:

<a href="http://www.stackoverflow.com/html_links.htm#hi"> 
Visit the hi Section</a> 
+0

this在页面加载时自动跳转到某个元素?我拒绝 – user677900

相关问题