Home  >  Article  >  Web Front-end  >  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
WBOYOriginal
2016-05-16 17:46:252163browse

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}
Statement:
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