请记住,表单 RESET 实际上不会清除所有字段,它也会将表单的默认值重置回默认值,因此更好的方法可能如下:
$('#the_form').trigger('reset');
Run Code Online (Sandbox Code Playgroud)
也许另一种方法:
// capture all existing values
var arr = [];
$(':input').each(function(i, e)
{
arr.push($(e).val());
});
// custom function to reset all values to initially captured values
function my_reset()
{
$(':input').each(function(i, e)
{
$(e).val(arr[i]);
});
}
Run Code Online (Sandbox Code Playgroud)
上述方法盲目地针对所有领域,如果你有办法更好地针对它们,你一定应该尽力而为。
此外,此方法按顺序存储所有字段,因此如果您有动态生成的字段,则必须修改此解决方案。
归档时间: |
|
查看次数: |
1167 次 |
最近记录: |