我正在使用 jQueryplugin 表单验证,效果很好,但它会在每个表单元素的右侧显示错误消息。我实际上希望每个表单元素的错误消息位于我自定义的特定 div 中。
例如:
这是我的验证 rules.js
$("#form").validate({
errorElement: "span",
//set the rules for the fields
rules: {
name: {
required: true,
minlength: 5,
maxlength:25
},
phone:{
required: true,
number: true,
minlength:10,
maxlength:11
},
email: {
required: true,
email: true
},
pswd: {
required: true,
minlength: 5,
maxlength:15
},
pswd1: {
required :true,
equalTo: "#pswd"
}
},
//set messages to appear inline
messages: {
name: {
required: "Name is required.."
},
pswd: {
required: "Please provide a password.",
minlength: "Your password must be at least 5 characters long",
maxlength: "Password can not be more than 15 characters"
},
pswd1:{
required: "Please re-Enter password.",
equalTo:"password not matching"
},
phone:{
required: "Please Enter phone no..",
number:"Not a valid phone number ",
minlength: "Not a valid phone number",
maxlength: "Phone No. cannot be more than 11 digit"
},
email: "Valid email is required.",
},
errorPlacement: function(error, element) {
error.appendTo(element.parent());
}
});
如果有人能告诉我你会怎么做,那将不胜感激。