jQuery在提交文本和复选框后清除表单字段 [英] jQuery to clear form fields after submit for text and checkbox

查看:89
本文介绍了jQuery在提交文本和复选框后清除表单字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在提交后清除表单字段(表单字段具有文本和复选框).为了清除表格,我创建了一个按钮.还有一个单独的提交按钮.

I want to clear the form fields (form fields has text and checkbox) after submit. To clear the form, I have created a button. And there is separate button for submit.

<input type="reset" name="clearform" id="clearform" value="Clear Form" />

<form id="submit" method="POST" action="">

我已经编写了jQuery代码,但是它不起作用:

I have written jQuery code but its not working:

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');
});

一个将清除所有文本输入.第二个将有助于取消选中复选框.

One will clear all text inputs. Second will help unchecking checkboxes.

希望有帮助.

这篇关于jQuery在提交文本和复选框后清除表单字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆