javascript平均数

来源:百度知道 编辑:UC知道 时间:2024/06/02 10:30:45
输入10位数字,累似于评分系统那样
去掉一个最高分和一个最低分,得出剩余8位数的平均分。
用javascript有没办法实现

数据输入的时候用空格分开,下面是源文件。

<html>
<head>
<title></title>
<script language="javascript" type="text/javascript">
function calavg() {
var t = document.getElementById("Text1").value;
m1 = t.split(" ");
if (m1.length < 3) {
document.getElementById("Text2").value = "数值数量少于3个。";
return;
}
var m2 = m1.sort();
var n = 0;
for (var i = 1; i<m2.length-1; i++) {
n = n + parseFloat(m2[i]);
}
var x = Math.round(n/(m2.length - 2)*1000)/1000;
document.getElementById("Text2").value = x;
}

</script>
<style type="text/css">
#Text2
{
width: 369px;
}
#Text1
{
width: 369px;
}
</style>
</head>
<body>

<p>
<input id="Text1" type="