學生行中有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值嗎? –