0

このコードは、テキストエリアにテキストを挿入できません。以下の html を参照してください。このスニペットは実際の Web ページを模倣しているため、html を変更できません。テキストエリアにテキストを挿入するだけです。

Chrome や IE9 では動作しません。

何か案は?

<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<script type="text/javascript">

function insert_text() {
   //enumerate div sections and find where id = WIN_0_4
   var div = window.document.getElementById("WIN_0_4");
   if(div !== null)
   {
      var txtbox = div.getElementsByTagName('textarea');
      if(txtbox !== null)
         txtbox.value = document.frm.texttoinsert.value;
   }
}

</script>

<form name="frm">
<input type="button" id="clicker" value="Click me" />
<input type="button" value="insert" id="inserter" onclick="insert_text();" />

<input type="text" name="texttoinsert" />
</form>


<div id="WIN_0_536870917" arid=536870917 artype="View" ardbn="View Field2"      class="arfid536870917 ardbnViewField2" style="color:#0000FF">
some text here
</div>

<div id="WIN_0_4" arid=4 artype="Char" ardbn="Assigned To">
<label id="label4" class="label f6">Assigned To</label>
<textarea class="text sr " wrap="off" id="arid_WIN_0_4" cols="20" maxlen=254 arautocak=0 arautoctt=400 rows=1></textarea>
</div>

</body>
</html>
4

2 に答える 2

1

交換

var txtbox = div.getElementsByTagName('textarea');

var txtbox = div.getElementsByTagName('textarea')[0];

またはそれ以上:

var txtbox = document.getElementById('arid_WIN_0_4');

名前が示すように、getElementsByTagName複数の要素を返します。

于 2013-01-01T18:02:59.153 に答える
0
txtbox[0].value = document.frm.texttoinsert.value;
于 2013-01-01T18:03:43.100 に答える