在使用jquery验证插件时重置表单 [英] Reseting the form when usering the jquery validations plugin

查看:69
本文介绍了在使用jquery验证插件时重置表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的表单,如下所示,我已将jQuery验证插件添加到( http:// docs.jquery.com/Plugins/Validation )。我在一个模态弹出窗口中有这个表单,所以如果有错误并且用户在再次打开它时关闭窗口,表单仍然有错误。在我的弹出关闭回调中,我尝试调用resetForm(),但它说该方法不存在。

I have a simple form like below that I have added the jQuery validations plugin onto (http://docs.jquery.com/Plugins/Validation). I have this form in a modal popup window so if there are errors and the user closes the window when they open it again the form still has the errors. In my popup close callback I tried calling resetForm() but it says the method doesn't exist.

表单HTML:

 <form class="validations" id="commentForm" method="get" action="">
   <p>
     <label for="name">Name</label>
     <em>*</em><input id="name" name="name" size="25" class="required" minlength="2" />
   </p>
   <p>
     <label for="email">E-Mail</label>
     <em>*</em><input id="email" name="email" size="25"  class="required email" />
   </p>
 </form>

弹出关闭回调:

function(){
  $(this).find('form.validations').resetForm();
}

预先感谢您的帮助。

推荐答案

resetForm 是validate方法返回的对象的一部分,而不是表单。示例:

resetForm is part of the object returned by the validate method, not the form. Example:

var validate = $('#commentForm').validate({ ... });
// Later...
validate.resetForm();
// Or if variable scope is in the way...
$('#commentForm').data('validator').resetForm();

验证插件在表单的数据存储中存储对验证对象的引用。

The validation plugin stores a reference to the validation object in the form's data store.

这篇关于在使用jquery验证插件时重置表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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