我的代码有什么问题?我创建了 6 个文本框。前五个框是用户想要的任何数字,最后一个框应该显示数字的平均值。我将不胜感激任何帮助!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/DTD/xhtml1.0-transitional.dtd"
<html xmlns="http://www.w3.org/1999/xhtml"
<head>
<title>Calc Average</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
/* <![CDATA[ */
var numberOne= 0;
var numberTwo = 0;
var numberThree = 0;
var numberFour = 0;
var numberFive = 0;
var calcResult = 0;
function calcAvg() {
performCalc(numberOne, numberTwo, numberThree, numberFour, numberFive);
return calcResult;
calcResult = document.numbers.averageResult.value;
}
function performCalc() {
calcResult = parseInt(numberOne + numberTwo + numberThree + numberFour + numberFive) / 5;
return calcAvg();
}
/* ]]> */
</script>
</head>
<body>
<form action="" name="numbers">
<table>
<tr>
<td>Number One</td>
<td>
<input type="text"
name="numOne" value="0" size="5"
onchange="var numberOne=calcAvg(document.numbers.numOne.value);" /></td>
</tr>
<tr>
<td>Number Two</td>
<td>
<input type="text"
name="numTwo" value="0" size="5"
onchange="var numberTwo=calcAvg(document.numbers.numTwo.value);" /></td>
</tr>
<tr>
<td>Number Three</td>
<td>
<input type="text"
name="numThree" value="0" size="5"
onchange="var numberThree=calcAvg(document.numbers.numThree.value);" /></td>
</tr>
<tr>
<td>Number Four</td>
<td>
<input type="text"
name="numFour" value="0" size="5"
onchange="var numberThree=calcAvg(document.numbers.numFour.value);" /></td>
</tr>
<tr>
<td>Number Five</td>
<td>
<input type="text"
name="numFive" value="0" size="5"
onchange="var numberFour=calcAvg(document.numbers.numFive.value);" /></td>
</tr>
<tr>
<td>Average of Five Numbers</td>
<td>
<input type="text"
name="averageResult" value="0" size="5"
onchange="calcAvg()" /></td>
</tr>
</table>
</body>
</html>