1、自定义方法(option)
$.validator.addMethod('needSelect',function (value,element) {
var jobCode =$('#position option:selected').attr('value');
return !(jobCode==0)
},'请选择面试岗位')
2、表单验证提交
$('.interviewSend').click(function () {
//表单校验
$('#form').validate({
rules:{
recipient:{
required:true,
email:true
},
subject:'required',
interviewTime:'required',
address:'required',
contact:'required',
mobile:{
required:true,
digits:true
},
job:'needSelect',
cc:'email',
contactMail:'email',
},
messages:{
recipient:{
required:'请输入收件人邮箱',
email:'请输入正确邮箱'
},
subject:'请输入邮件正文',
interviewTime:'请选择面试时间',
address:'请输入面试地点',
contact:'请输入联系人',
mobile:{
required:'请输入联系方式',
digits:'请输入正确手机号 '
},
cc:'请输入正确邮箱',
contactMail:'请输入正确邮箱'
},
// errorPlacement:function(error,element){
// layer.tips($(error).text(),element,{ tipsMore: true,time:1000});
// },
submitHandler:function () {
//校验成功执行ajax
layer.load(1);
var uploadJson =serializeFormDataToJsonObj($('#form').serialize());
uploadJson.interviewTime =$('input[name=interviewTime]').val();
uploadJson.positionName =$('#position option:selected').text();
$.ajax({
url:'/recruitJob/saveInterViewNotice',
type:'POST',
timeout:5000,
contentType:'application/json; charset=UTF-8',
data:JSON.stringify(uploadJson),
success:function (i) {
layer.closeAll('loading');
if(i.result ===1001){
layer.msg('邀请成功,即将关闭本页面');
setTimeout("window.close()",2000)
}else{
layer.msg(i.resultInfo);
}
}
});
}
});
$('#form').submit();
});
网友评论