jquery验证相互依赖的字段对
我需要验证表单中的一组姓名、手机号码字段。为了方便使用服务器端脚本,我用数组表示法(即方括号)命名了字段。 此外,下面的同一个html会重复多次,具体取决于需要多少条记录jquery验证相互依赖的字段对,jquery,validation,Jquery,Validation,我需要验证表单中的一组姓名、手机号码字段。为了方便使用服务器端脚本,我用数组表示法(即方括号)命名了字段。 此外,下面的同一个html会重复多次,具体取决于需要多少条记录 <table width="100%" border="0"> <tr><td class="b_name"><label>Name <sup>*</sup></label></td><td class="b_mobile"
<table width="100%" border="0">
<tr><td class="b_name"><label>Name <sup>*</sup></label></td><td class="b_mobile"><label>Mobile <sup>*</sup></label></td><td class="removetext"><a href="javascript:void(0);" onclick="removebroadcast(this);" id="remove_<?php echo $cnt;?>">Remove</a></td></tr>
<tr><td class="b_name" id="name_<?php echo $cnt;?>"><input type="text" value="" name="broadcast_name[]" class="broadcast_name" /></td><td class="b_mobile" id="mobile_<?php echo $cnt;?>"><input type="text" value="" name="broadcast_mobile[]" class="broadcast_num" /></td><td id="message_<?php echo $cnt;?>"> </td></tr>
</table>
但是,这仅适用于第一组名称/移动字段。我还尝试了其他一些技巧(例如,使用$。每个类型验证,使用自定义规则函数等),但它们似乎都不起作用。这里有什么我做错的吗?请帮忙(您可能想查看电话字段: 你不能做点像这样的事吗
$('form').submit(function(e){
var errors = false;
$(this).find('input').each(function(){
if($(this).val() === ''){
errors = true;
}
});
if(errors){
e.preventDefault();
alert('errors exist');
}
});
感谢mask插件,但实际上我一直在电话领域使用它,只是不认为有必要提供所有细节。关于提供的解决方案,我需要具体使用jquery验证插件,如果您之前不清楚,我深表歉意。不客气,我想知道为什么我的答案对您不起作用霍夫
$('form').submit(function(e){
var errors = false;
$(this).find('input').each(function(){
if($(this).val() === ''){
errors = true;
}
});
if(errors){
e.preventDefault();
alert('errors exist');
}
});