2011-10-08 63 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

相關問題