将value传递给textarea

七 8th, 2009

预设一些值,然后通过Button, 链接将这些值传递给textarea作为内容,或者作为textarea内容的其中一部分

在前台表单十分常见。以下为2个例子:

A 将ABCDE或者FGHIJ传递给textarea:

<textarea id="A1" cols="20" rows="2"></textarea>
<input onclick="document.getElementById('A1').value=this.value" name="Submit1" type="button" value="ABCDE" />
<input onclick="document.getElementById('A1').value=this.value" name="Submit2" type="button" value="FGHIJ" />

效果:

B 在textarea当前光标焦点插入内容:

<form name="form1">
<table>
<tr>
<td><textarea name="A1" id="" cols="45" rows="3"></textarea></td>
</tr>
<tr>
<td><input type="button" value="吃饭"onclick="chifan()" />
<input type="button" value="吃菜"onclick="chicai()" /></td></tr>
</table>
</form>

  <script>
  function   chifan(){
  document.form1.A1.focus()
  document.selection.createRange().text="吃饭;"
  }
  function   chicai(){
  document.form1.A1.focus()
  document.selection.createRange().text="吃菜;"
  }
  </script>

效果:

标签:
目前还没有任何评论.

阀门 电动调节阀 调节阀 丝袜