我正在开发一个Web应用程序,我使用 jquery验证:
$("#register").validate({
rules: {
emailID: {
required: true,
email: true
},
pass: {
required: true,
minlength: 6
},
user_email: {
required: true,
email: true
},
user_pass: {
required: true,
minlength: 6
}
}
一切正常,但问题是对象emailID
和user_email
两者的{strong>相同数据对{{1}也相同}和pass
,我怎样才能将它们排成一行而不更改html中的user_pass
属性,如下所示:
name
我知道这种结构不正确。
因为我有很多对象拥有相同的数据,所以在重复
中似乎不太好答案 0 :(得分:2)
function RequiredRule( email, minlength ) {
this.email = email;
this.minlength = minlength;
this.required = true;
}
$("#register").validate({
rules: {
emailID: new RequiredRule(true),
pass: new RequiredRule(false, 6),
user_email: new RequiredRule(true),
user_pass: new RequiredRule(false, 6)
}
});
答案 1 :(得分:1)
var one = {
required: true,
email: true
},
two = {
required: true,
minlength: 6
};
$("#register").validate({
rules: {
emailID: one,
pass: two,
user_email: one,
user_pass: two
}
});