我有一个ID为form_select
)的表单,其中包含2个错误类(errorIdentification
和errorIdentification1
)。
$('#form_select').validate({
rules: {
'user_name' : {
required: true
},
'password' : {
required: true
}
},
messages: {
'user_name' : {
required: 'From date is required!'
},
'password' : {
required: 'To date is required!'
}
},
errorClass: **'errorIdentification'**,
errorPlacement: function(err, element) {
err.insertBefore(element);
},
submitHandler: function(form) {
form.submit();
}
});
$('#form_select').validate({
rules: {
'from' : {
required: true
},
'to' : {
required: true
}
},
messages: {
'from' : {
required: 'From date is required!'
},
'to' : {
required: 'To date is required!'
}
},
errorClass: **'errorIdentification1'**,
errorPlacement: function(err, element) {
err.insertBefore(element);
},
submitHandler: function(form) {
form.submit();
}
});
问题在于验证表单,所有字段(用户名,密码,from和to)都获得相同的errorClass errorIdentification
,这是(用户名和密码)的第一个错误类
如何使用不同的错误类实现此功能?
答案 0 :(得分:0)
更改您的第二个表单脚本,如;
$('#form_select').validate({
rules: {
'from' : {
required: true
},
'to' : {
required: true
}
},
messages: {
'from' : {
required: 'From date is required!'
},
'to' : {
required: 'To date is required!'
}
},
errorClass: **'errorIdentification1'**,
errorPlacement: function(err, element) {
err.insertBefore(element);
},
submitHandler: function(form) {
form.submit();
}
});