我正在尝试获得 4 分的平均值并将其传递到文本字段中。
它确实得到了平均值,唯一不起作用的部分是该grade.value = grade;
部分
这是我的代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Week #10 JavaScript Assignment: Problem #1</title>
<script type = "text/javascript">
function calcgrade(one,two,three,four){
sum = parseInt(one.value) + parseInt(two.value) + parseInt(three.value) + parseInt(four.value);
grade = sum / 4;
grade.value = grade;
}
</script>
</head>
<body>
<h1>Calculate Grade</h1>
<form>
<table>
<tr>
<th>Assignment #</th>
<th>Grade</th>
</tr>
<tr>
<td>1</td>
<td><input type="text" id="one" name="one"></td>
</tr>
<tr>
<td>2</td>
<td><input type="text" id="two" name="two"></td>
</tr>
<tr>
<td>3</td>
<td><input type="text" id="three" name="three"></td>
</tr>
<tr>
<td>4</td>
<td><input type="text" id="four" name="four"></td>
</tr>
<tr><td colspan="2"><input type="button" onclick="calcgrade(one, two, three, four)" value="Calculate Grade"></td></tr>
<tr>
<td>Grade:</td>
<td><input type="text" id="grade" name="grade"></td>
</tr>
</td>
</form>
</body>
</html>