2012-07-13 44 views
0

我想刪除或清除錯誤消息並重置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> 

回答

2

使用resetForm()

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