提交后在同一页面中显示html表单值

提交后在同一页面中显示html表单值

问题描述:

我有一个HTML表单,我需要在用户单击提交按钮后在表单下方显示表单域值。如何使用HTML和JavaScript来做到这一点?

I have a HTML form and I need to display the form field values below the form after user clicks the submit button. How can I do this using HTML and JavaScript?

这是一种方法。 b

Here is one way to do it.

<!DOCTYPE html>
<html>
  <head lang="en">
  <meta charset="UTF-8">
  <script language="JavaScript">
    function showInput() {
        document.getElementById('display').innerHTML = 
                    document.getElementById("user_input").value;
    }
  </script>

  </head>
<body>

  <form>
    <label><b>Enter a Message</b></label>
    <input type="text" name="message" id="user_input">
  </form>

  <input type="submit" onclick="showInput();"><br/>
  <label>Your input: </label>
  <p><span id='display'></span></p>
</body>
</html>

这就是run.Cheers的样子。

And this is what it looks like when run.Cheers.