我是一名刚刚学习 HTML 的大学生。我必须完成的作业是一个简单的成绩计算器。有一个按钮可以计算所有内容,值转到三个空文本字段(总计、平均值和百分比)。我遇到的问题是总数被计算并显示在字段中,但数字后面是 [object]。平均字段显示 NaN,百分比字段保持为空。这是我的代码。
<input type="button" value="Click to calculate"
onclick="fullmark = parseFloat(document.getElementById('fullBox').value);
science = parseFloat(document.getElementById ('scienceBox').value);
math = parseFloat(document.getElementById('mathBox').value);
computer = parseFloat(document.getElementById('computerBox').value);
english = parseFloat(document.getElementById('englishBox').value);
History = parseFloat(document.getElementById('historyBox').value);
total=science+math+computer+english+history;
average=(total/5);
percentage=(total/fullmark)*100;
document.getElementById('totalBox').value=total;
document.getElementById('averageBox').value=average;
document.getElementById('percentageBox').value=percentage;">