A new understanding of the Form Form reset method

  • 2020-03-30 02:16:33
  • OfStack

The reset method of the HTML Form is used to clear the user's input, which has been mistakenly thought to simply clear the value of an input item such as input.

The essence of the reset method is to restore the contents of an input item, such as input, to the value of the attribute value, instead of a "" null value.

The w3c says:

In the HTML form < Input type = "reset" > Each time the label appears, a Reset object is created.

When the reset button is clicked, the values of all input elements in the containing form are reset to their default values. The defaultValue is specified by the HTML value attribute or the defaultValue attribute of JavaScript.

In practice, we often need to implement a form reset when editing something, but at this time, the value attribute of an input item such as input might already be assigned a value, so reset simply initializes the form to that value.

In this case, we can only use javascript to set the value attribute of input and other input items to null to achieve the reset effect.

Related articles: