我的表格中有3个字段。我想验证Name,Age和错误类,Total_score和另一个错误类。这是一个包含单个id的表单。我怎么能这样做。
$('#form1').validate({
rules: {
'Name' : {
required : true
},
'Age' : {
required: true
},
'Total_score' : {
required: true
}
},
messages: {
'Name' : {
required: 'From date is required!'
},
'Age' : {
required: 'To date is required!'
},
'Total_score' : {
required: 'Score is required!'
}
},
errorClass: '?????',
errorPlacement: function(err, element) {
err.insertBefore(element);
},
submitHandler: function(form) {
form.submit();
}
});
答案 0 :(得分:2)
尝试类似
的内容<input name="Name" data-errorclass="error-name"/>
然后
$('#form1').validate({
rules: {
'Name' : {
required : true
},
'Age' : {
required: true
},
'Total_score' : {
required: true
}
},
messages: {
'Name' : {
required: 'From date is required!'
},
'Age' : {
required: 'To date is required!'
},
'Total_score' : {
required: 'From date is required!'
}
},
errorPlacement: function(err, element) {
err.addClass(element.data('errorclass'))
err.insertBefore(element);
},
submitHandler: function(form) {
form.submit();
}
});
演示:Fiddle