通过Divs迭代

时间:2011-11-30 04:51:32

标签: javascript jquery loops for-loop

for (i = 1; i < total.length; i++) {
    $("div.category:nth-of-type(" + i + ") ul.qItem li :input[type=radio]:checked").each(function() {
        total[i] += parseInt($(this).val());
        $("div.category:nth-of-type(" + i + ") div.report div.scorebox").html(total[i] + " / 15");
    });
    if (total[i] > 11) {
        $("div.category:nth-of-type(" + i + ") div.t12").toggle();
        $("div.category:nth-of-type(" + i + ") div.report div.scorebox").css("color", "green");
        $("div.category:nth-of-type(" + i + ") div.report span.opinion").html(high).css("color", "green");
    } else if (total[i] < 7) {
        $("div.category:nth-of-type(" + i + ") div.t6").toggle();
        $("div.category:nth-of-type(" + i + ") div.report div.scorebox").css("color", "#900");
        $("div.category:nth-of-type(" + i + ") div.report span.opinion").html(low).css("color", "#900");
    } else {
        $("div.category:nth-of-type(" + i + ") div.t711").toggle();
        $("div.category:nth-of-type(" + i + ") div.report div.scorebox").css("color", "orange");
        $("div.category:nth-of-type(" + i + ") div.report span.opinion").html(medium).css("color", "orange");
    }
}

这个for循环应该迭代5个div并对每个中选择的输入单选按钮的值求和。然后它应该在记分箱中输出5个类别中每个类别的分数。根据3个范围,它应该对其性能(低,中,高)输出不同的意见,为文本红色,橙色或绿色着色,并切换一些文本提供建议的可见性(t6,t711,t12)。不幸的是,它似乎无法将得分放在记分板中或选择要显示的正确文本。任何人都可以建议如何让这个脚本依次对每个div进行操作吗?

1 个答案:

答案 0 :(得分:4)

jQuery内置了这个。

$('selector').each(function(index, element) {

});

$(selector).each()

相关问题