我有这段代码:
<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>
中说“工作”,但它不起作用。关于如何解决它的任何想法?
答案 0 :(得分:3)
始终如一地设置value
属性,而不是innerHTML
属性和拼写terminal
。