我正在创建一个需要验证字段的Web应用程序。 .js正在加载,但是它给出了Uncaught TypeError:undefined不是第2行$("#adduser-form").validate({
的函数错误。请告诉我我做错了什么。以下是我的验证文件代码:
$(document).ready(function() {
$("#adduser-form").validate({
rules : {
email : {
required : true,
email : true,
maxlength : 64
},
firstname : {
required : true,
minlength : 3,
maxlength : 32
},
lastname : {
maxlength : 32,
minlength : 3,
required : true
},
password : {
maxlength : 32,
minlength : 8,
required : true
},
company : {
maxlength : 64,
minlength : 3,
required : false
},
title : {
maxlength : 64,
minlength : 3,
required : false
}
},
messages : {
email: {
required: "Email is required.",
email: "Please enter a valid Email address."
},
firstname: {
required:"First Name is required."
},
lastname: {
required:"Last Name is required."
},
password: {
required:"Password is required.",
},
},
invalidHandler : function(event, validator) {//display error alert on form submit
$('.alert-error', $('#adduser-form')).show();
},
highlight : function(element) {// hightlight error inputs
$(element).closest('.control-group').addClass('error');
// set error class to the control group
},
success : function(label) {
label.closest('.control-group').removeClass('error');
label.remove();
},
errorPlacement : function(error, element) {
error.addClass('help-small no-left-padding').insertAfter(element.closest('.input-icon'));
},
submitHandler : function(form) {
form.submit();
}
});
$('#adduser-form input').keypress(function(e) {
if (e.which == 13) {
if ($('#adduser-form').validate().form()) {
$('#adduser-form').submit();
}
return false;
}
});
});
答案 0 :(得分:0)
我没有包含jQuery验证库。我加入了它,它就像一个魅力!