Resetting a form in jquery is primarily about converting jquery into DOM objects, using the Reset () method , so there are two scenarios:
One: Use Get (0)
$ ("#myform"). Get (0). Reset ();
Two: use [0]
$ ("#myform") [0].reset ();
These two methods are in fact consistent with the principle of use;
But here's one thing to note:
Sometimes when you use both of these methods, the browser
typeerror:$ ("..."). Get (...). Resetisnotafunction
Error, this condition may be the reset button in the form defines an exception;
<form id= "MyForm" action= "method=" POST "> User name: <input name=" name "value=" "><br> Password: <input type = "Password" name= "PSW" ><br> <input type= "Submit" id= "SM" value= "Login" > <br> <input type= "reset "id=" reset "value=" Reset ><br></form>
The reason for this is that the id= "reset" in the deadweight button should be set id= "reset" may overwrite the original "Reset ()" method, so the reset () is undefined.
Since the reset button will appear such a problem, then submit will not also appear such a problem, interested can try it yourself ^ ^
This article is from the "Yinbin" blog, make sure to keep this source http://yinbin99.blog.51cto.com/11392662/1853691
Form Reset in JSP