我有一堆像这样的田野在空中创造
<input type="text" name="coeff_a">
<input type="text" name="coeff_b">
<input type="text" name="coeff_c"> .. and so on ..
我想验证上述字段的输入,并使用jquery validate插件。我制定了这样的规则
jQuery.validator.addMethod(
"perc",
function(value, element) {
var coeff = $("input[name^='coeff']");
var total;
for (var i = 0; i < coeff.length; i++) {
total += coeff[i].value;
}
if (total <= 100) {
return true;
}
return false;
},
jQuery.format("Please ensure percentages don't add up to more than 100")
);
不用说,上述方法不起作用。知道我做错了什么吗?