未捕获的TypeError:无法读取未定义的属性“call”
我有一个预先存在的表单,我正在尝试添加jqueryvalidation包含:
使用jqueryvalidation器插件,我添加了:
$('form').validate({ rules: { first_name: { minlen: 3, maxlength: 15, required: true }, last_name: { minlength: 3, maxlength: 15, required: true }, email: { required: true, email: true }, phone1: { required: true, phoneUS: true }, phone2: { required: true, phoneUS: true }, street: { required: true }, city: { required: true }, state: { required: true }, zip: { zipcodeUS: true } }, highlight: function(element) { $(element).closest('.style9').addClass('.style13'); //$(element).addClass('.style13'); }, unhighlight: function(element) { $(element).closest('.style9').removeClass('.style13'); //$(element).removeClass('.style13'); }, errorElement: 'span', errorClass: 'style13', errorPlacement: function(error, element) { if(element.parent('.input-group').length) { error.insertAfter(element.parent()); } else { error.insertAfter(element); } } });
我收到上面列出的错误。 我究竟做错了什么?
用minlen
替换minlen
,它有效,没有minlen
属性,所以内部call
失败
$('form').validate({ rules: { first_name: { minlength: 3, // <- here maxlength: 15, required: true }, last_name: { minlength: 3, maxlength: 15, required: true }, ..........
一般来说,如果您设置了无效的jQueryvalidation规则,则可以引发此错误。
您可以使用此链接找到有效的validation规则。
尝试
jQuery(document).ready(function(){ $('form').validate({ rules: { first_name: { minlen: 3, maxlength: 15, required: true }, last_name: { minlength: 3, maxlength: 15, required: true }, email: { required: true, email: true }, phone1: { required: true, phoneUS: true }, phone2: { required: true, phoneUS: true }, street: { required: true }, city: { required: true }, state: { required: true }, zip: { zipcodeUS: true } }, highlight: function(element) { $(element).closest('.style9').addClass('.style13'); //$(element).addClass('.style13'); }, unhighlight: function(element) { $(element).closest('.style9').removeClass('.style13'); //$(element).removeClass('.style13'); }, errorElement: 'span', errorClass: 'style13', errorPlacement: function(error, element) { if(element.parent('.input-group').length) { error.insertAfter(element.parent()); } else { error.insertAfter(element); } } }); });