<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=1i<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>