jS合计列值怎么写(JS高手请进)?
发布网友
发布时间:2022-05-12 18:31
我来回答
共2个回答
热心网友
时间:2023-10-17 19:16
<table name ="table1" width="285" border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="109">数量</td>
<td width="41">单价</td>
<td width="91">金额</td>
</tr>
<tr>
<td name1="td11" onchange="sum()">10</td>
<td name1="td12"onchange="sum()">2</td>
<td name1="td13"onchange="sum()"> 20</td>
</tr>
<tr>
<td name1="td21"onchange="sum()">15</td>
<td name1="td22"onchange="sum()">3</td>
<td name1="td23"onchange="sum()">45</td>
</tr>
..
..
..
<tr>
<td name1="total1">合计数量:</td>
<td name1="total2" colspan="2">合计金额:</td>
</tr>
</table>
<script>
function sum()
{
var obj = document.getElementById("table1");
var length = obj.rows.length ;
var sum1 =0;
var sum2 =0;
for(int i=1;i<length-1 ;i++)
{
sum1 =parseFloat(sum1) + parseFloat(document.getElementById ("td"+i+""+1).value);
sum2 =parseFloat(sum2) + parseFloat(document.getElementById ("td"+i+""+3).value);
}
document.getElementById ("total1").value = sum1;
document.getElementById ("total2").value = sum2;
}
</script>
热心网友
时间:2023-10-17 19:16
数据库每读一行的时候存一个累加变量啊,最后在合计数量那里输出不就行了
<%
sum=sum+rs("数量")
%>