//日历插件
$('.date-picker').datepicker({
format: "yyyy-mm-dd",
todayBtn: "linked",
clearBtn: true,
language: "zh-CN",
todayHighlight: true,
orientation: "bottom auto",
autoclose: true
});
$(document).ready(function () {
$("#adEditForm").validate({
errorPlacement: function (error, element) {
var eid = element.attr('name');
console.log(eid);
console.log(element);
if (element.is('#adName')){
console.log(error);
error.appendTo(element.parent());
}else if (element.is("#adDesc")){
error.appendTo(element.parent());
}else if (element.is("#startTime")){
error.appendTo(element.parent());
}else if (element.is("#endTime")){
error.appendTo(element.parent());
}else {
error.insertAfter(element);
}
},
onfocusout: function (element) {
var checkValid = $(element).valid();
if (false == checkValid){
$("#save").attr("disabled", true);
}
},
rules: {
adName: {
required: true,
minlength: 1,
maxlength: 24,
},
// adDesc: {
// required: false,
// minlength: 0,
// maxlenght: 400,
// },
startTime: {
required: true,
},
endTime: {
required: true,
},
adUploaderImage: {
required: true,
},
},
messages: {
adName: {
require: '广告名称需为1-24个字符',
minlength: '广告名称需为1-24个字符',
maxlength: '广告名称需为1-24个字符',
},
// adDesc: {
// require: '广告描述需为0-400个字符',
// minlength: '广告描述需为0-400个字符',
// maxlength: '广告描述需为0-400个字符',
// },
startTime: {
},
endTime: {
},
adUploaderImage: {
require: '请上传图片',
},
},
success: "valid"
});
$("#adName").focus(function () {
});
$("#save").click(function () {
var isValidSuccess = $("#adEditForm").valid();
if (!isValidSuccess) {
$("#save").attr("disabled", true);
return;
}
})
});