javascript 将表单重置为默认值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3610289/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 01:43:08  来源:igfitidea点击:

reset a form to the default values

javascriptjquerydefault-value

提问by kalpaitch

Currently I have:

目前我有:

$("#your_email").val(this.defaultValue;)

I want to be cycling through all form elements and resetting them to their default value

我想循环浏览所有表单元素并将它们重置为默认值

回答by brad

you don't need jQuery for this, just get the form dom element and call reset() on it.

为此,您不需要 jQuery,只需获取表单 dom 元素并在其上调用 reset()。

Or, fetch with jQuery like:

或者,使用 jQuery 获取,例如:

$("#myFormId")[0].reset();