SoFunction
Updated on 2025-04-03

New understanding of Form form reset method

The reset method of Form form in HTML is used to clear the content entered by the user. I used to mistakenly think that it is simply clearing the values ​​in input and other input items.

But in fact, this is not the case. The essence of the reset method is to restore the contents in input items such as input to the value in the property value, rather than the ""null value.

This is what w3c says:

In the HTML form, a Reset object is created every time the <input type="reset"> tag appears.

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

In actual situations, we often need to implement form reset when editing a certain content, but at this time the value attributes of input items such as input may have been assigned a value, so reset just makes the form initialize to this value.

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