<form name="form1" method="post" action="">
<?php
for($i=0;$i<5;$i++){
?>
<tr>
<td><input name="a1[]" type="text" size="20" ></td>
<td><input name="a2[]" type="text" size="10" onBlur="ja()"></td>
<td><input name="a3[]" type="text" size="20"></td>
<br />
</tr>
<?php
}
?>
<td><input name="a3" type="text" size="20"></td>
<td><input type="submit" value=" 注册 " class="button"></td>
</form>
<script type="text/javascript">
function ja(){var a=0;
for(var i=0;i<5;i++){
document.getElementsByName("a3[]")[i].value=document.getElementsByName("a2[]")[i].valuedocument.getElementsByName("a1[]")[i].value ;
a=parseInt(a)+parseInt(document.getElementsByName("a3[]")[i].value);}
document.getElementsByName("a3")[0].value=a;
}
</script>
保留2位小数
function ja(){var a=0.00;
for(var i=0;i<document.getElementsByName("a3[]").length;i++){
document.getElementsByName("a3[]")[i].value=(document.getElementsByName("a2[]")[i].valuedocument.getElementsByName("a1[]")[i].value).toFixed(2) ;
a=parseFloat(a) + parseFloat(document.getElementsByName("a3[]")[i].value);}
document.getElementsByName("a3")[0].value=a.toFixed(2);