jQuery验证依赖字段 [英] Jquery validate depend field
本文介绍了jQuery验证依赖字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
伙计们,
我正在尝试使用jQuery验证插件,并指定仅当其他3个字段为空白(未填充)时才需要一个字段.
I am trying to use jQuery validation plugin and specify that one field is required only when 3 other fields are blank (not filled).
问题是规则在起作用,但是即使我在其中输入值,它仍然需要该字段.
the thing is that the rule is working but it still remain requiring the field even when I type value on it.
谢谢.
这是我的代码:
$("#ProspectDtlFrm").validate({
rules: {
prsptEmail: {
required: function(element) { return ( $("#prsptHomePhone").val() == '' && $("#prsptBusinessPhone").val() == '' && $("#prsptMobilePhone").val() =='') }
}
},
messages: {
prsptEmail: "Please enter your first name"
}
});
推荐答案
您可以使用depends
:
$('#ProspectDtlFrm').validate({
rules: {
prsptEmail: {
required: {
depends: function(element) {
return ($('#prsptHomePhone').val() == '' &&
$('#prsptBusinessPhone').val() == '' &&
$('#prsptMobilePhone').val() == '');
}
}
}
},
messages: {
prsptEmail: 'Please enter your first name'
}
});
这篇关于jQuery验证依赖字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文