日期:2014-05-16 浏览次数:20350 次
用window.scrollTo(xPoint,yPoint)来实现,回到顶部用window.scrollTo(0,0);
Example:
<html>
<head>
<title>window.scrollTo()函数</title>
<script laguage="javascript">
<!--
function scrollwin(form)
{
var winx=form.X.value;
var winy=form.Y.value;
window.scrollTo(winx,winy);
}
//-->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form>
<table border=0 align=center>
<tr>
<td colspan=3 align=center bgcolor=lightgreen><font color=blue size=3>
请输入窗口的位置:</font></td></tr>
<tr>
<td><input type=text name="X" style="background-color:lightblue;color:blue"></td>
<td><input type=text name="Y" style="background-color:lightblue;color:blue"></td>
<td><input type=button value="scroll window" onclick=scrollwin(this.form) style="background-color:ligntblue;"></td>
</tr>
</table>
</form>
</body>
</html>