2012-04-04 16 views
1

我有這段代碼在我的jQuery驗證腳本:jQuery的復位形式值+無效錯誤

resetForm: function() { 
     if ($.fn.resetForm) 
      $(this.currentForm).resetForm(); 
     this.submitted = {}; 
     this.prepareForm(); 
     this.hideErrors(); 
     this.elements().removeClass(this.settings.errorClass); 
    } 

這正是我需要的,因此,我想用它。我試圖將它與onclick綁定,但沒有成功。我只需要一個調用此函數的按鈕/鏈接。你能在這方面給我建議嗎?

+0

凡定義的功能?它看起來像一個選項對象的內部,這意味着它將不可訪問。 – 2012-04-04 13:56:17

+0

這是一個默認的JQuery驗證函數(包含在jquery.validate.js中)。它應該可以在驗證器對象上調用http://docs.jquery.com/Plugins/Validation/Validator/resetForm – mattytommo 2012-04-04 14:22:13

回答

3

如果你試試這個,它應該工作(假定你有一個id爲myButton和一種叫做myForm的一個按鈕):

$("#myButton").click(function() { 
    var validator = $("#myform").validate(); 
    validator.resetForm(); 
}); 
+0

是的謝謝你,這是正確的答案:) – 2012-04-04 15:01:06

+0

沒問題,很高興它幫助:) – mattytommo 2012-04-04 15:02:19

+0

只是一個說明:如果表單被隱藏(display:none),這不起作用。 所以有必要在使用resetForm之前顯示它。 – ferhrosa 2014-08-27 12:32:40