我有
$("#myForm").validate({
....
rules: {
phone1: {
required: {
depends: "!#pri_noPhone:checked"
},
number: true,
minlength:3,
}
它不会抛出错误,但仍会尝试验证电话号码。
答案 0 :(得分:7)
尝试这样的事情:
"#phone1": {
number: true,
minlength:3,
required: function(element){
return ($('#pri_noPhone_wrapper input:checked').val() == 'True');
}
}
HTML(看了之后我忘了添加包装HTML)
<span id='pri_noPhone_wrapper'>
Phone:
<input type="checkbox" name="pri_noPhone" value="what ever" />
</span>
答案 1 :(得分:2)
我认为您希望使用正确的选择器语法指定您的依赖项:
required: {
depends: "#pri_noPhone:not(:checked)"
}
修改强>
史蒂夫在电子邮件中回答:
confirmEmail: {
required:true,
equalTo: "#email"
},
答案 2 :(得分:2)
您可以使用以下内容:
$("#myForm").validate({
rules: {
username: {
email: {
required:true,
email:true,
maxlength:255,
},
confirmEmail: {
required:true,
equalTo: "#email"
},
}
}
})