【发布时间】:2020-04-20 21:56:21
【问题描述】:
我正在使用 jquery 验证插件来验证复杂的输入数组。
HTML 表单
<form class="test_frm" action="" method="post" >
<input class="form-control" type="text" name="rateType[0][type]" />
<input class="form-control" type="text" name="rateType[0][rate]" />
<input class="form-control" type="text" name="rateType[0][percent]" />
<input class="form-control" type="text" name="rateType[1][type]" />
<input class="form-control" type="text" name="rateType[1][rate]" />
<input class="form-control" type="text" name="rateType[1][percent]" />
<input class="form-control" type="text" name="rateType[2][type]" />
<input class="form-control" type="text" name="rateType[2][rate]" />
<input class="form-control" type="text" name="rateType[2][percent]" />
</form>
JS代码
$(function () {
$(".test_frm").validate({
submitHandler: function (form) {
form.submit();
},
ignore: [],
rules: {
'rateType[]': {
required: true
}
}
});
});
我需要验证的是如果至少填写了一个文本输入应该是正确的。但是即使它适用于简单的数组输入,此代码也不起作用。如果有人知道如何做到这一点,那将是一个很大的帮助。如果 它不依赖于 [0] 或 [type] 之类的数组值,那就太好了。
【问题讨论】: