Jquey quickly empties the form content method with too many fields

  • 2020-03-30 03:44:10
  • OfStack

Made a complex query of the page, too many fields, filled once, want to clear the trouble


$('#myform')[0].reset();

The reset method can do this in part, but if you have an element that looks like this


<input name="percent" value="50"/>

Then clicking reset will only restore 50

So, with the following method, browse the Internet,


$(':input','#myform') 
.not(':button, :submit, :reset, :hidden') 
.val('') 
.removeAttr('checked') 
.removeAttr('selected');

Related articles: