从 textarea 中检索文本

Wal*_*ife 2 html javascript textarea

<textarea></textarea>在我的 html 页面上,想根据用户输入的内容从中检索信息。假设用户在 textarea 中键入“Hello”。“你好吗”将出现。

像这样(代码实际上不起作用,只是一个例子:

<script>    
    if ('msg'.value === "hello") {
        document.write("How are you");
    }
</script>
<textarea  id="msg"></textarea>
<input type="submit></input>
Run Code Online (Sandbox Code Playgroud)

希望有人能帮帮我!

编辑:在提交时输出 msg val。

谢谢!

Ano*_*ous 5

'msg'是一个字符串。你需要一个元素:

if (document.getElementById('msg').value === "hello") {
    document.write("How are you");
}
Run Code Online (Sandbox Code Playgroud)