我有形式。this.init不是一個函數的jQuery驗證插件在我反應過來的應用程序,它通過jQuery驗證插件驗證反應程序
let validator = $('form').validate({
errorClass: 'has-error',
errorElement:'label',
});
validator.form();
if ($('.has-error').length > 0) {
$('.has-error').each(function (index) {
$.validator().showErrors({prop:$(this).data('error')});
});
} else {
/*work with data*/
}
所有錯誤的消息顯示正常,但每次當驗證觸發的時候,我得到錯誤控制檯:
this.init is not a function
和LINK我的代碼的插件,腳本:
$.validator = function(options, form) {
this.settings = $.extend(true, {}, $.validator.defaults, options);
this.currentForm = form;
this.init();
};
如何我可以修復它嗎? UPD 1:下面的插件腳本代碼,我發現這個代碼:
$.extend($.validator, {
//some code
prototype: {
init: function() {
this.labelContainer = $(this.settings.errorLabelContainer);
this.errorContext = this.labelContainer.length && this.labelContainer || $(this.currentForm);
this.containers = $(this.settings.errorContainer).add(this.settings.errorLabelContainer);
this.submitted = {};
this.valueCache = {};
this.pendingRequest = 0;
this.pending = {};
this.invalid = {};
this.reset();
//some code
也許它激發因爲這個初始化函數的錯誤異常?
你在哪裏定義'init'方法? –
我沒有定義init方法,它在插件腳本里面定義,查看更新的問題。 –