如何将文本打印到textarea?

时间:2013-09-01 20:05:15

标签: javascript html

我有这段代码:

<script type="text/javascript">
    function GetChar(event) {
        var chCode = ('charCode' in event) ? event.charCode : event.keyCode;
        if (chCode == 13) {
            var textBox = document.getElementById('TEXTBOX');
            alert("The text in the box is: " + textBox.value);
            document.getElementById('test').innerHTML = ("The text in the box is: " + textBox.value);
            if (textBox.value == 'ninja') document.getElementById('teraminal').innerHTML = ("working!")
        }
    }
</script>

HTML:

<input type="text" id="TEXTBOX" size="40" value="" onKeyPress="GetChar (event);" />
<label id="test"></label>
<textarea rows="40" cols="80" readonly id="terminal" draggable="false" style="resize:none">

当我输入“ninja”时,我希望它在<textarea>中说“工作”,但它不起作用。关于如何解决它的任何想法?

1 个答案:

答案 0 :(得分:3)

始终如一地设置value属性,而不是innerHTML属性和拼写terminal