Php jQuery验证名称数组,必需的名称数组
我在使用jQuery验证插件时遇到了一些麻烦 我有一个表单,其中包含一些名称数组复选框和相应的名称数组无线电输入 我要做的是,只有在检查了(非必需的)check[]输入后,才验证action[]输入Php jQuery验证名称数组,必需的名称数组,php,jquery,arrays,validation,Php,Jquery,Arrays,Validation,我在使用jQuery验证插件时遇到了一些麻烦 我有一个表单,其中包含一些名称数组复选框和相应的名称数组无线电输入 我要做的是,只有在检查了(非必需的)check[]输入后,才验证action[]输入 $(document).ready(function(){ $("#testForm").validate({ rules: { 'action[]': { required: function () {
$(document).ready(function(){
$("#testForm").validate({
rules: {
'action[]': {
required: function () {
return $("'check[]':checked");
}
}
}
});
});
包括
行动
第[0]行:
在
关闭
第[1]行:
在
关闭
我已经建立了一个JSFIDLE,希望能更详细地解释这个问题:
任何帮助或指导都将不胜感激
提前感谢jsFIDLE目前似乎不适合我,所以我会在回复后尽快更新答案 验证插件提供了
依赖
选项
请像这样尝试:
$("#testForm").validate({
rules: {
'action[]': {
depends: function () {
return $("check[]").is(":checked"); //here you need to target the needed checkbox, not all of them
}
}
}
});
你可以试试类似的东西
jQuery.validator.addClassRules(“需要操作”{
所需:功能(el){
return$(el).closest('tr').find('input[name^=“check”]”)。is(':checked')
}
});
$(“#testForm”).validate({});
//因为代码段不允许表单提交
$(':按钮')。单击(函数(){
console.log($(“#testForm”).valid()
})
包括
行动
第[0]行:
在
关闭
第[1]行:
在
关闭