在HTML中,一般人使用滾動像頁首:滾動頂級java腳本函數?
<a href="#top" title="Scroll back to the top">Back to the top</a>
但我需要的網頁去點擊鏈接後頂部。 文件left.php的:
<div class"ida0">
<a href="news.php" target="right_frame" onclick="scrollToTop()">Link 1</a>
</div>
因爲我的網頁是這樣的。 * main.php * left.php * right.php
| ---------------------------- |
| ---------------------------- |
|| some image ||內容|
|| ---------------- ||鏈接||
|| ---------------- || -------- ||
|| ---------------- || -------- ||
|| ---------------- || -------- ||
|| ----- link1 ------ || -------- ||
|| ----- link2 ------ || -------- ||
|| ---------------- || -------- ||
|| ---------------- || -------- ||
我用這個但是沒有工作。
<script language="javascript">
function scrollToTop()
{
document.getElementById(ida0).scrollTop = 0; //It scrolls to top
}
</script>
當我把代碼「window.scroll(0,0);」在「left.php」文件中,點擊鏈接,它運行良好,走到了窗口頂部。但是,當我打開main.php,並點擊左邊的鏈接.php它沒有奏效。 – trante
@trante:試試'window.top.scroll(0,0);'。 – Ryan
很酷。非常感謝你。 – trante