假设您有一个循环,并根据循环的结果向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

    });


什么是这样做的好方法?

谢谢

最佳答案

$('.Y') // Will give you all the Y class elements
$('.N') // Will give you all the N class elements

09-12 01:34