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上运行?遍历整个div
请张贴例如HTML太 –
您的代码看起来不错,只要这两个假设是正确的:1)你有插件或扩展的jQuery以支持nth类型的选择器,2)你的HTML的结构是一堆'category'divs,在每个div里面都是'advice'div和'report'div;在'报告'div里面是'记分框'和'意见'。 – rkw