textarea取值

来源:百度知道 编辑:UC知道 时间:2024/05/05 19:55:15
怎样在javascript中取到textarea的值放到文本框里?

<script>
function writeText(){
document.getElementById("mytxt").value=document.getElementById("myarea").value;
}
</script>

<textarea name="a" cols="60" rows="10" id="myarea"></textarea>
<input type="button" onclick="writeText()" value="area到文本"/>
<input onclick="writeText()" id="mytxt"/>

可以使用document.表单名.文本域名.value来接收javascript中设定的值.这里用document.getElementById是没用的.
写了一个可能对你有提示:
<script>
function aa(){
txt="I Love China ";
document.form1.a.value+=txt;}
</script>
<input type="button" onclick="aa()" value="多次把“I Love China”加到textarea"/>
<form id="form1" name="form1" method="post" action="">
<textarea name="a" cols="60" row