使用jQuery提交后清除表单

刷新后清除此表单最简单的方法是什么? 我尝试的方式将清除表单但不提交到数据库。 有人可以向我解释最好的方法。

     jQuery(document).ready(function($){ $("#newsletterform").validate({ debug: false, rules: { name: "required", email: { required: true, email: true } }, messages: { name: "Please let us know who you are.", email: "A valid email will help us get in touch with you.", }, submitHandler: function(form) { // do other stuff for a valid form $.post('newsletter.php', $("#newsletterform").serialize(), function(data) { $('#results').html(data); }); } }); });   

Sign up for News, Updates, and Offers!

您可以将此添加到$.post的回调中

 $( '#newsletterform' ).each(function(){ this.reset(); }); 

你不能只调用$( '#newsletterform' ).reset()因为.reset()是一个表单对象而不是一个jquery对象,或者是那种效果。 您可以在这里阅读有关它的更多信息。

您可以使用以下方式重置表单:

 $("#myform")[0].reset(); 

使用jQuery重置表单的更好方法是在表单上trigger reset事件。

 $("#btn1").click(function () { $("form").trigger("reset"); }); 

在你的post方法回调函数中尝试这个

 $(':input','#myform') .not(':button, :submit, :reset, :hidden') .val('') .removeAttr('checked') .removeAttr('selected'); 

了解更多信息请阅读此内容

这对你来说是可行的。

  $('input').val('').removeAttr('checked').removeAttr('selected'); 

只需将它添加到某个div或td中的Action文件中,以便它带有传入的XML对象

   

其中“formname”是您要编辑的表单的ID