Home > Web Front-end > JS Tutorial > jQuery implements the form form reset button to reset and clear the form function_jquery

jQuery implements the form form reset button to reset and clear the form function_jquery

WBOY
Release: 2016-05-16 17:46:25
Original
2214 people have browsed it

Sometimes you may need to achieve this effect: use ajax to submit the form, and clear the form after successfully submitting the form, as follows:

Copy code The code is as follows:

After clicking submit, the content is submitted through ajax.
In the past, I used the following code to clear the form
Copy the code The code is as follows:

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

I accidentally thought of another method a few days ago (if you know the following Friends of the method can stop here):
Copy code The code is as follows:

//In Add a hidden reset button to the form,

//Then trigger the reset button through trigger
function subform( ){
/* ...
*Code part to submit the form
* ... */
$("input[type=reset]").trigger("click"); //Trigger reset button}
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