【发布时间】:2016-12-29 23:09:54
【问题描述】:
我正在使用下面的代码来重置我在特定表单上的所有值。
$('#' + frm).closest('form').find("input[type=text], textarea").val("");
$('#' + frm).closest('form').find("input[type=password]").val("");
$('#' + frm).find('input[type=checkbox]:checked').removeAttr('checked');
$('#' + frm + ' input[type="radio"]').prop('checked', false);
它适用于 95% 的情况,但我想将所有“选择”框重置为选定的索引 0。如果有更好或更有效的方法来完成整个过程来重置所有元素类型,我我愿意接受最好的建议。我需要重置表单,因为同一个人会一遍又一遍地使用相同的表单来添加工作经历。
感谢您的意见
【问题讨论】:
-
document.querySelector("form").reset()?
标签: javascript jquery