2011-02-16 73 views

回答

8

您可以在window.onload元素上使用scrollIntoView事件..

在你的情況,你會做:

window.onload = function() { 
    var el = document.getElementById('target'); 
    el.scrollIntoView(true); 
} 

良好的文檔可以在這裏找到: MDN scrollIntoView

2

你的身體標籤也更改爲類似

<body onload="ScrollToTarget"> 

那麼你的功能,可以在頭被定義爲

function ScrollToTarget() 
{ 
    document.getElementById("target").scrollIntoView(true); 
}