<html>
<head>
<title></title>
<script language="javascript">
var num=0;
function add()
{
var name=document.getElementById("na").value;
var yuwen=document.getElementById("yu").value;
var shuxue=document.getElementById("shu").value;
var waiyu=document.getElementById("wai").value;
var newitemcheck = document.createElement("<input type='checkbox' id=check"+num+">");
document.getElementById("item").insertAdjacentElement("beforeEnd",newitemcheck);
document.getElementById("item").insertAdjacentText("beforeEnd","姓名:");
var newitemname = document.createElement("<input type='text' size='4' id=na"+num+ ">");
document.getElementById("item").insertAdjacentElement("beforeEnd",newitemname);
document.getElementById("na"+num).value=name;
document.getElementById("item").insertAdjacentText("beforeEnd","语文:");
var newitemyuwen = document.createElement("<input type='text' size='4' id=yu"+num+ ">");
document.getElementById("item").insertAdjacentElement("beforeEnd",newitemyuwen);
document.getElementById("yu"+num).value=yuwen;
document.getElementById("item").insertAdjacentText("beforeEnd","数学:");
var newitemshuxue = document.createElement("<input type='text' size='4' id=shu"+num+ ">");
document.getElementById("item").insertAdjacentElement("beforeEnd",newitemshuxue);
document.getElementById("shu"+num).value=shuxue;
document.getElementById("item").insertAdjacentText("beforeEnd","外语:");
var newitemwaiyu = document.createElement("<input type='text' size='4' id=wai"+num+ ">");
document.getElementById("item").insertAdjacentElement("beforeEnd",newitemwaiyu);
document.getElementById("wai"+num).value=waiyu;
document.getElementById("item").insertAdjacentHTML("beforeEnd","<br>");
}
function count()
{
var total=0;
var a=0;
var b=0;
var c=0;
for(var i=1;i<=num;i++)
{
if(document.getElementById("check"+i).checked)
{
a+=parseInt(document.getElementById("yu"+i).value);
b+=parseInt(document.getElementById("shu"+i).value);
c+=parseInt(document.getElementById("wai"+i).value);
total++;
}
}
a=a/total;
b=b/total;
c=c/total;
document.getElementById("count").style.display="block";
document.getElementById("wen").innerText="语文:"+a;
document.getElementById("xue").innerText="数学:"+b;
document.getElementById("ying").innerText="外语:"+c;
}
</script>
</head>
<body>
姓名:<input type="text" name="na" id="na" size="4">
语文:<input type="text" name="yu" id="yu" size="4">
数学:<input type="text" name="shu" id="shu" size="4">
外语:<input type="text" name="wai" id="wai" size="4">
<input type="button" value="增加记录" onclick="num++;add();">
<br>
<span id="item"></span>
<br>
<span id="count" style="display:none;">平均成绩:<span id="wen"></span><span id="xue"></span><span id="ying"></span></span>
<input type="button" value="计算平均成绩" onclick="count()">
</body>
</html>