文本域怎样自动滚屏?

来源:百度知道 编辑:UC知道 时间:2024/06/21 23:50:19
在HTML中有个textarea,它在内容多的时候,会出现上下滚动条。
但是内容慢慢增多的时候,内容直接在原始文本后面追加,但是滚动条需要手动调整。
怎样才能使滚动条随之内容的增多,自动下滚?

可以使用javascript

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function setTextScroll(){
var text = document.getElementById("scroll_text");
var time = null;
var step = 100; //数字越小越快
function begin(){
text.scrollTop++;
time = setTimeout(begin, step);
}
text.onmouseover = function(){ clearTimeout(time); }
text.onmouseout = function(){ setTimeout(begin, step); }
begi