Asp 多行表单,每行输入数据后自动计算结果?
多行表单,想每行输入数字后,最后一个表单自动计算结果每行都这样,这个代码怎么写啊?请教各位大侠了没有分了,希望大家帮忙,参考下面的列子,比如输入语文,数学英语分数后,自动...
多行表单,想每行输入数字后,最后一个表单自动计算结果
每行都这样,这个代码怎么写啊?请教各位大侠了
没有分了,希望大家帮忙,参考下面的列子,比如输入语文,数学英语分数后,自动计算出总分,每行都是这样
姓名 语文 数学 英语 总分
A __ __ __ ___
B __ __ __ ___
C __ __ __ ___ 展开
每行都这样,这个代码怎么写啊?请教各位大侠了
没有分了,希望大家帮忙,参考下面的列子,比如输入语文,数学英语分数后,自动计算出总分,每行都是这样
姓名 语文 数学 英语 总分
A __ __ __ ___
B __ __ __ ___
C __ __ __ ___ 展开
2个回答
展开全部
这个很容易的
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<script language="JavaScript" type="text/javascript">
function AddToTotal(id1,id2,id3,id4)
{
var o1 = document.getElementById(id1);
var o2 = document.getElementById(id2);
var o3 = document.getElementById(id3);
var o4 = document.getElementById(id4);
var total = 0;
if ( o1.value != "" )
total += parseInt(o1.value);
if ( o2.value != "" )
total += parseInt(o2.value);
if ( o3.value != "" )
total += parseInt(o3.value);
o4.value = total;
}
</script>
<form name="form1" method="post" action="">
<table width="800" border="0" cellspacing="0" cellpadding="5">
<tr>
<td>姓名</td>
<td>语文</td>
<td>数学</td>
<td>英语</td>
<td>总分</td>
</tr> <tr>
<td width="45">A</td>
<td width="182"><input name="Ya" type="text" id="Ya" onChange="AddToTotal('Ya','Sa','Ea','Ta')"></td>
<td width="181"><input name="Sa" type="text" id="Sa" onChange="AddToTotal('Ya','Sa','Ea','Ta')"></td>
<td width="195"><input name="Ea" type="text" id="Ea" onChange="AddToTotal('Ya','Sa','Ea','Ta')"></td>
<td width="197"><input name="Ta" type="text" id="Ta" onChange="AddToTotal('Ya','Sa','Ea','Ta')"></td>
</tr>
<tr>
<td>B</td>
<td width="182"><input name="Yb" type="text" id="Yb" onChange="AddToTotal('Yb','Sb','Eb','Tb')"></td>
<td width="181"><input name="Sb" type="text" id="Sb" onChange="AddToTotal('Yb','Sb','Eb','Tb')"></td>
<td width="195"><input name="Eb" type="text" id="Eb" onChange="AddToTotal('Yb','Sb','Eb','Tb')"></td>
<td width="197"><input name="Tb" type="text" id="Tb" onChange="AddToTotal('Yb','Sb','Eb','Tb')"></td>
</tr>
<tr>
<td>C</td>
<td width="182"><input name="Yc" type="text" id="Yc" onChange="AddToTotal('Yc','Sc','Ec','Tc')"></td>
<td width="181"><input name="Sc" type="text" id="Sc" onChange="AddToTotal('Yc','Sc','Ec','Tc')"></td>
<td width="195"><input name="Ec" type="text" id="Ec" onChange="AddToTotal('Yc','Sc','Ec','Tc')"></td>
<td width="197"><input name="Tc" type="text" id="Tc" onChange="AddToTotal('Yc','Sc','Ec','Tc')"></td>
</tr>
</table>
</form>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<script language="JavaScript" type="text/javascript">
function AddToTotal(id1,id2,id3,id4)
{
var o1 = document.getElementById(id1);
var o2 = document.getElementById(id2);
var o3 = document.getElementById(id3);
var o4 = document.getElementById(id4);
var total = 0;
if ( o1.value != "" )
total += parseInt(o1.value);
if ( o2.value != "" )
total += parseInt(o2.value);
if ( o3.value != "" )
total += parseInt(o3.value);
o4.value = total;
}
</script>
<form name="form1" method="post" action="">
<table width="800" border="0" cellspacing="0" cellpadding="5">
<tr>
<td>姓名</td>
<td>语文</td>
<td>数学</td>
<td>英语</td>
<td>总分</td>
</tr> <tr>
<td width="45">A</td>
<td width="182"><input name="Ya" type="text" id="Ya" onChange="AddToTotal('Ya','Sa','Ea','Ta')"></td>
<td width="181"><input name="Sa" type="text" id="Sa" onChange="AddToTotal('Ya','Sa','Ea','Ta')"></td>
<td width="195"><input name="Ea" type="text" id="Ea" onChange="AddToTotal('Ya','Sa','Ea','Ta')"></td>
<td width="197"><input name="Ta" type="text" id="Ta" onChange="AddToTotal('Ya','Sa','Ea','Ta')"></td>
</tr>
<tr>
<td>B</td>
<td width="182"><input name="Yb" type="text" id="Yb" onChange="AddToTotal('Yb','Sb','Eb','Tb')"></td>
<td width="181"><input name="Sb" type="text" id="Sb" onChange="AddToTotal('Yb','Sb','Eb','Tb')"></td>
<td width="195"><input name="Eb" type="text" id="Eb" onChange="AddToTotal('Yb','Sb','Eb','Tb')"></td>
<td width="197"><input name="Tb" type="text" id="Tb" onChange="AddToTotal('Yb','Sb','Eb','Tb')"></td>
</tr>
<tr>
<td>C</td>
<td width="182"><input name="Yc" type="text" id="Yc" onChange="AddToTotal('Yc','Sc','Ec','Tc')"></td>
<td width="181"><input name="Sc" type="text" id="Sc" onChange="AddToTotal('Yc','Sc','Ec','Tc')"></td>
<td width="195"><input name="Ec" type="text" id="Ec" onChange="AddToTotal('Yc','Sc','Ec','Tc')"></td>
<td width="197"><input name="Tc" type="text" id="Tc" onChange="AddToTotal('Yc','Sc','Ec','Tc')"></td>
</tr>
</table>
</form>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询