如何使用jquery验证重置错误消息?

时间:2012-07-13 11:17:47

标签: javascript jquery-ui jquery-validate jquery

我想删除或清除错误消息并在点击取消按钮时重置jquery验证。

这里我给了我的代码:

$(document).ready(function() {
    var validator = $("#loginForm").validate({
        messages: {
            email: {
                required: "Please enter email.",
                email: "Please enter a valid email."
            },
            password: "Please enter password."
        }
    });

     <form name="loginForm" id="loginForm" method="post" action="javascript:login();">
                        <div class="login_contain_div">
                             <div id="login_errors" class="errors"></div>
                             <div class="login_contain_inner">

                                  <span style="font-size: 20px; font-weight: lighter;">Email</span>
                                  <input type="text" id="email" name="email" class="inputbg required email" />

                                  <br/>
                                  <span style="font-size: 20px; font-weight: lighter;">Password:</span>
                                  <input type="password" id="password" name="password" class="inputbg required" />
                             </div>
                             <div class="login_button_area">

                                  <input type="submit" id="login_submit" class="login_greenbtn button_float_left login_btn_width" name="submit" value="Ok" style="cursor: pointer;" />
                                  <a class="ptr login_greenbtn button_float_right login_btn_width" onClick="$('#cboxClose').click();">Cancel</a>
                             </div>
                        </div>
                   </form>

1 个答案:

答案 0 :(得分:2)

使用resetForm()

 $(".cancel").click(function() {
   validator.resetForm();
 )};