假设您有一个循环并根据循环的结果向DIV添加类名,Y或N.基于Y或N,您想要更改该类的css属性。请参阅以下代码:
function percentageCount() {
$(".Parent").children().each(function(i, valOuter) { // Outer Loop
alert("Outer loop");
alert($(valOuter).html());
var totalPercentage = 0;
$(valOuter).children().find(':input').each(function(ii, valInner) { // Inner Loop
// alert("Inner loop");
totalPercentage += parseInt(this.value);
// alert("total percentage: " + totalPercentage);
if (this.value == '') {
totalPercentage += 0; // Assume empty string == 0
}
if (totalPercentage == 100) {
alert("Percentage equals to 100");
$(valOuter).removeClass("N");
$(valOuter).addClass("Y");
}
else {
alert("Percentage must equal to 100");
$(valOuter).removeClass("Y");
$(valOuter).addClass("N");
}
}); // Inner Loop
}); // Outer Loop
// Code to search for JQuery class
});
这样做的好方法是什么?
由于
答案 0 :(得分:3)
$('.Y') // Will give you all the Y class elements
$('.N') // Will give you all the N class elements