jQuery / Javascript函数清除表单的所有字段 [英] jQuery/Javascript function to clear all the fields of a form

查看:151
本文介绍了jQuery / Javascript函数清除表单的所有字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个jQuery函数,它会在提交表单后清除表单的所有字段。

I am looking for a jQuery function that will clear all the fields of a form after having submitted the form.

我没有任何要显示的HTML代码,我需要一些通用的东西。

I do not have any HTML code to show, I need something generic.

你能帮忙吗?

谢谢!

推荐答案

注意:此答案与重置表单字段相关,而不是清除字段 - 请参阅更新。

Note: this answer is relevant to resetting form fields, not clearing fields - see update.

您可以使用JavaScript的原生 reset() 重置整个表单到默认状态的方法。

You can use JavaScript's native reset() method to reset the entire form to its default state.

示例由 Ryan 提供:

$('#myForm')[0].reset();

注意:这可能无法重置某些字段,例如 type =hidden

Note: This may not reset certain fields, such as type="hidden".

如前所述 IlyaDoroshin 使用jQuery的 触发器()

As noted by IlyaDoroshin the same thing can be accomplished using jQuery's trigger():

$('#myForm').trigger("reset");



更新



如果你需要做除了重置表单到默认状态,您应该查看使用jQuery重置多阶段表单

UPDATE

If you need to do more than reset the form to its default state, you should review the answers to Resetting a multi-stage form with jQuery.

这篇关于jQuery / Javascript函数清除表单的所有字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆