表单验证插件validate代码片段

2019年10月15日

$(“#contactForm”).validate({

rules: {
name: {
required: true,
},
time: {
required: true,
},
country: {
required: true,
},
edu: {
required: true,
},
job: {
required: true,
},
email: {
required: true,
email:true,
},
sex:{
required: true,
}
},
messages: {
name: {
required: “请输入姓名”,
},
time: {
required: “请输入出生年月”,
},
country: {
required: “请输入国籍”,
},
edu: {
required: “请输入最高学历”,
},
job: {
required: “请输入担任职务”,
},
email: {
required: “请输入邮箱地址”,
email:”请输入正确的邮箱地址”,
},
sex: {
required: “请选择性别”,
},
},
submitHandler:function(form){
alert(“提交事件!”);

},
errorPlacement : function(error, element) {
// //console.log($(element).attr(‘type’));
// //if (element.is(“:text”)){
if ($(element).attr(‘type’)==’radio’){
error.appendTo(element.parent().next());
//console.log(1);
}
else{
error.appendTo(element.parent());
}
//error.appendTo(element.next());
},

});

登陆后查看全部内容