function ScrollDiv() { var ex = document.getElementById("calm"); ex.scrollTop = ex.scrollHeight; }
obj.scrollTop:滚动条距离顶部的位置
obj.scrollHeight:流动区域的高度
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JS控制DIV滚动条</title>
</head>
<script>
function scrollup()
{
document.getElementById('div1').scrollTop = document.getElementById('div1').scrollTop-25;
}
function scrolldown()
{
document.getElementById('div1').scrollTop = document.getElementById('div1').scrollTop+25;
}
function scrolltop()
{
document.getElementById('div1').scrollTop = 0;
}
function scrollbottom()
{
document.getElementById('div1').scrollTop = document.getElementById('div1').scrollHeight;
}
</script>
<style>
.div1
{
height:200px;
overflow-y:scroll;
width:400px;
border:solid 1px #ccc;
}
</style>
<body>
<div class="div1" id="div1"><br />
start<br />
<br /><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
middle<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
end<br />
</div>
<input name="" type="button" value="向上"/ οnclick="scrollup();">
<input name="" type="button" value="向下" οnclick="scrolldown();"/>
<input name="" type="button" value="顶"/ οnclick="scrolltop();">
<input name="" type="button" value="底" οnclick="scrollbottom();"/>
</body>
</html>