form

Written by with ♥ on in _

表单事件

  • reset
  • submit

reset

重置表单中的所有元素的值

<input type="reset" value="reset">

or

<input type="button" onclick="resetForm()" value="reset">

function resetForm() {
    document.getElementById("id-form").reset();
}

submit

提交表单

<form id="id-form1" action="/action">
  First name: <input type="text" name="fname"><br>
  Last name: <input type="text" name="lname"><br><br>
  <input type="button" onclick="myFunction()" value="Submit form">
</form>

<script>
function myFunction() {
    document.getElementById("id-form1").submit();
}
</script>