-5
<div class="main">
<textarea rows ="20" cols="80" name ="output_box" id ="output"></textarea>
</div>

私がやりたいのは、ボタンのクリックでその領域にテキストを追加することです

<div class="classname"  button type =onclick="myFunction()" >
    Export
</div>

そして、これはそれが呼ぶものです

<script>
    function myFunction()
     {
         var obj = document.getElementById("output").innerHTML;
         var text = document.createTextNode("Test data");
         obj.innerHTML = text;
     }
</script>

しかし、多くの欲求不満の後、私はそれを理解できません。

4

1 に答える 1

1

Example with the changes below: http://jsfiddle.net/charlescarver/hZw6q/

Your JS should be closer to this:

var obj = document.getElementById("output");
var txt = "Test data";
obj.value = txt;
  1. txt != text
  2. As Matt Ball pointed out, "obj is a string," not an object.
  3. You don't need document.createTextNode as you're using value instead of innerHtml

Your HTML should also be:

<div class="classname" type="button" onClick="myFunction()">
    Export
</div>

And not:

<div class="classname"  button type =onclick="myFunction()" >
    Export
</div>
于 2013-06-30T04:05:55.497 に答える