JQueryValidation

这里是我写的一些操作实例。


$(document).ready(function() {

$('#form_save').validate(
{
submitHandler:function(){
save();
},
rules: {
BATCH_CODE: {
required: true,
minlength: 2
},
BATCH_STARTDATE: {
required: true
},
BATCH_ENDDATE:{
required: true
},
BATCH_PLANNEDSTARTDATE:{
required:true
},
BATCH_PLANNEDENDDATE:{
required:true
},
CENTER_ID:{
required:true
},
FACULTY_ID:{
required:true
},
SEMESTER_ID:{
required:true
},
},
messages: {
BATCH_CODE: {
required: "请输入班级编码",
minlength: "班级编码必须由两个以上字符组成"
},
BATCH_STARTDATE: {
required: "班级开班时间不能为空"
},
BATCH_ENDDATE:{
required: "班级结束时间不能为空"
},
BATCH_PLANNEDSTARTDATE:{
required:"班级计划开班时间不能为空"
},
BATCH_PLANNEDENDDATE:{
required:"班级计划结班时间不能为空"
},
CENTER_ID:{
required:"请选择所属中心"
},
FACULTY_ID:{
required:"请选择代班老师"
},
SEMESTER_ID:{
required:"请选择所属老师"
},
},
highlight: function (element) { // hightlight error inputs
$(element)
.closest('.form-group').addClass('has-error'); // set error class to the control group
},
unhighlight: function (element) { // revert the change done by hightlight
$(element)
.closest('.form-group').removeClass('has-error'); // set error class to the control group
},
errorPlacement: function(error, element) {
//添加错误信息到找到第一个类为form-group的祖先元素中去,即加在出错元素后。
//element:指代出错的input元素;error:指代出错之后要加的信息,有message就用其,没有message就用title,
//没有title最后使用内置默认自带信息
//验证规则分两种:内置,自定义:内置的自带默认message,自定义的需要自己填加
error.appendTo($(element).parents("div.form-group")[0]);
},
errorClass:"col-md-5 text-danger"
});
});

你可能感兴趣的:(JQueryValidation)