Home  >  Article  >  Web Front-end  >  使用jQuery重置(reset)表单的方法_jquery

使用jQuery重置(reset)表单的方法_jquery

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

由于JQuery中,提交表单是像下面这样的:

复制代码 代码如下:
$('#yigeform').submit()


所以,想当然的认为,重置表单,当然就是像下面这样子喽:
复制代码 代码如下:
$('#yigeform').reset()


但是,不幸的是,这样写的话,会有一个让你很郁闷的结果,那就是,表单无法重置!

后来,上网查了一下,说是,JQuery中没有reset方法,经核对,果然是没有。

那有么没有办法通过JQuery来重置表单呢,答案是有的,不过是一种间接的方法,如下:

复制代码 代码如下:
$('#yigeform')[0].reset()

也就是通过调用 DOM 中的reset方法来重置表单。
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