我使用以下代码在提交后重置我的表单。
function resetForm($form) {
$form.find('input:text, input:password, input:file, select, textarea').val('');
$form.find('input:radio, input:checkbox')
.removeAttr('checked').removeAttr('selected');
}
但是,我确实有两个不受支持的输入 block ,即 input:time
和 input:number
。
我找到了一种解决方法,并为有效的时间 block 添加了 input[name=action_time]
。但是,我的数字字段有一个更复杂的名称 name=action[qty][]
因此,当添加 input[name=action[qty][]]
时,我得到 语法错误
。
最佳答案
如果您有复杂的名称,请尝试使用引号,如下例所示:
$('input[name="action[qty][]"]').val('');
或者您可以为您的输入
提供一个类属性,并使用类选择器.
来重置它:
HTML:
<input type="number" class='qty' name='action[qty][]' />
JS:
$('.qty').val('');
希望这有帮助。
关于javascript - 复位输入:number after submit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33913730/