怎样用js实现向textarea追加内容?
怎样用js实现向textarea追加内容,原来的内容保持不变,然后用js脚本实现回车换行然后向textarea追加字符串?能否举个例子,把源码传上来?急,在线等!先谢谢了。
<html>
<head>
<title>动态添加html元素</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script>
function a()
{
var e=document.getElementById("t");
var str="";
e.focus();
e.innerText="ping 192.168.0.1 with 32 bytes of data:\n";
str=e.value;
setTimeout("append(document.getElementById('t').value,'0')",1000);
setTimeout("append(document.getElementById('t').value,'0')",2000);
setTimeout("append(document.getElementById('t').value,'0')",3000);
setTimeout("append(document.getElementById('t').value,'0')",4000);
setTimeout("append(document.getElementById('t').value,'1')",5000);
}
function append(str,sec_para)
{
var e=document.getElementById("t");
var textarea_value="", appEndData="";
if(sec_para==0)
appEndData="Reply from 192.168.0.1: bytes=32 time=1ms TTL=64\n";
else if(sec_para==1)
appEndData="Ping statistics for 192.168.0.1:\n\rPackets: Sent = 4, Received = 4, Lost = 0 (0% loss),\nApproximate round trip times in milli-seconds:\n\rMinimum = 0ms, Maximum = 1ms, Average = 0ms;";
textarea_value=str+appEndData;
e.value=textarea_value;
}
</script>
</head>
<body>
<a href="javascript:void(0)" onClick="a();">test</a>
<textarea id="t" cols="100" rows="30">abc</textarea>
</body>
</html>