我正在使用下面的代码来重置特定表单上的所有值。
$('#' + 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。如果有更好或更有效的方法来执行整个过程来重置所有元素类型我我们愿意接受最好的建议。我需要重置表单,因为同一个人会一遍又一遍地使用同一张表单来添加工作经历。
感谢您的参与
最佳答案
您可以使用 Form reset() Method
The reset() method resets the values of all elements in a form (same as clicking the Reset button).
$('#' + frm).closest('form')[0].reset();
关于javascript - 使用 jQuery 清除表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41382094/