2

我有这个代码:

<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">

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

4

1 回答 1

3

设置value属性,而不是innerHTML属性和拼写terminal一致。

于 2013-09-01T20:06:20.807 回答