Commonly used emptying a form
| The code is as follows |
Copy Code |
$ (': input ', ' #myform ') . Not (': button,: Submit,: RESET,: Hidden ') . Val (") . removeattr (' checked ') . Removeattr (' selected '); |
Cases
| The code is as follows |
Copy Code |
$ (' #myform ') [0].reset (); |
Although the Reset method can do a part, but if you have an element that is like this
| The code is as follows |
Copy Code |
| <input name= "percent" value= "/>" |
Then click Reset will only revert to 50
Sometimes you might want to do this by submitting the form with Ajax, emptying the form after the form has been successfully submitted, and following this code:
| The code is as follows |
Copy Code |
<form> <input name= "Name1"/><br/> <input name= "Name1"/><br/> <textarea name= "Content" ></textarea> <a href= "javascript:void (0)" onclick= "subform ()" > Submit </a> </form> |
After clicking Submit, the content is submitted via Ajax.
I used the following code to clear the form
| The code is as follows |
Copy Code |
$ ("input"). Val ('); $ ("textarea"). Val (');
|
The previous days have no intention of thinking of another method (if you know the following method friends can stop there):
| code is as follows |
copy code |
| //In form forms Add a hidden reset button, <input type= "reset" style= "Display:none;"/> //Then trigger the Reset button function by trigger Subform () { /* ... * Submit the code portion of the form * ... * * $ ("Input[type=reset]"). Trigger ("click");//Trigger reset button} |