I got it working this way:
Custom validation rule:
$.validator.addMethod(
"sum",
function (value, element, params) {
var sumOfVals = 0;
var parent = $(element).parent(".parentDiv");
$(parent).find("input").each(function () {
sumOfVals = sumOfVals + parseInt($(this).val(), 10);
});
if (sumOfVals == params) return true;
return false;
},
jQuery.format("Sum must be {0}")
);
And using like this:
$(".group1").rules('add', {sum: 100});
$(".group2").rules('add', {sum: 100});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…