学生行中有m students
和n criteria
列,同一行中有总列。但是只有在相应行中输入数字时,总数才能动态计算。需要什么修改?以这种方式,总结第一行中的所有输入。但只需要逐行求和。在输入对应行中的数字时动态计算 - Javascript
<script>
var num=[];
function recalculate(rowData,studCode) {
var n = document.getElementById('criteria_count').value;
num.push(parseFloat(document.getElementById('criteria_mark_'+rowData).value));
var total=0;
for (var i = 0; i <n; i++) {
total = total + parseFloat(num[i]) ;
if (!isNaN(total)) {
document.getElementById('total_mark_'+studCode).value = Math.round(total);
}
}
}
</script>
你应该在每一行指定列迭代,你的循环不代表。 for循环条件语句表示我
n是criteria_count。我现在纠正了。但仍然存在问题。 – Dayz
您现在正在将criteria_count的.value值转换为float值,我不完全确定要在条件语句中使用float值吗? –