0
我有一大堆的領域像飛這樣創建jQuery的驗證插件 - 跨多個輸入驗證規則字段
<input type="text" name="coeff_a">
<input type="text" name="coeff_b">
<input type="text" name="coeff_c"> .. and so on ..
我想驗證輸入到上述領域,並使用jQuery驗證插件是。我已經建立了一個規則,像這樣
jQuery.validator.addMethod(
"perc",
function(value, element) {
// all the fields that start with 'coeff'
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")
);
不用說,上述不工作。任何想法我做錯了什麼?
是的!做到了!謝謝。 – punkish 2010-07-17 13:09:07