我想在提交后清除表单字段(表单字段有文本和复选框).为了清除表单,我创建了一个按钮.还有单独的提交按钮.
<input type="reset" name="clearform" id="clearform" value="Clear Form" /> <form id="submit" method="POST" action="">
我编写了jQuery代码,但它不起作用:
jQuery("#clearform").click(function(){ jQuery("#submit input[type='text'],input[type='checkBox']").each(function() { this.value = ''; }); });
解决方法
试试这个:
$('#clearform').on('click',function () { $('#form_id').find('input:text').val(''); $('input:checkBox').removeAttr('checked'); });
一个人将清除所有文本输入.第二个将帮助取消选中复选框.
希望能帮助到你.