Home > Web Front-end > JS Tutorial > jquery js reset form reset() specific implementation code_jquery

jquery js reset form reset() specific implementation code_jquery

WBOY
Release: 2016-05-16 17:26:40
Original
970 people have browsed it

During development, we will use many forms. We hope that the form can be reset after it is submitted.
But jquery does not have this method. How to deal with it?

Copy code The code is as follows:





Method 1:
We can implement
id:
Copy code The code is as follows:

document.getElementById("form1").reset();

name:
Copy code The code is as follows:

document.formName.reset();

Method 2:
Clear one by one:
Copy code The code is as follows:

$("#inp").val("1");

But if there are too many forms, this is not practical. There are 100 or 1000. You can’t write 100 or 1000.
Maybe you will say, write it like this:
Copy the code The code is as follows:

$ ("input").val("");

What about the default value of the form? There are other types of forms, write them all?
Add input of type reset
Copy code The code is as follows:



< input id="res" name="res" type="reset" style="display:none;" />


Copy code The code is as follows:

$("input[name='res']").click();

Clear all forms
ok
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template