Home >Web Front-end >JS Tutorial >How to reset a form using jQuery_jquery

How to reset a form using jQuery_jquery

WBOY
WBOYOriginal
2016-05-16 16:49:521706browse

Since in JQuery, the submission form looks like the following:

Copy the code The code is as follows:
$('#yigeform').submit()


So, it is taken for granted that resetting the form is like this:
Copy code The code is as follows:
$('#yigeform').reset()


But, unfortunately, this If you write, there will be a very depressing result, that is, the form cannot be reset!

Later, I checked online and found out that there is no reset method in JQuery. After checking, it turns out that there is no reset method.

So is there no way to reset the form through JQuery? The answer is yes, but it is an indirect method, as follows:

Copy code The code is as follows:
$('#yigeform')[0].reset()

That is, the form is reset by calling the reset method in the DOM.
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