日期:2014-05-17  浏览次数:20851 次

我想在输入前二个单元格信息时,最后一个能自动把原来的二个值相加
我想在输入前二个单元格信息时,最后一个能自动把原来的二个值相加
不知道怎么操作,谢谢
<table   width= "100% "   border= "0 "   cellpadding= "0 "   cellspacing= "1 ">
<tr>
  <td   > <input   name= "Yearsffd2 "> </td>
  <td   > <input   name= "Yearsffd "> </td>
    <td   > <input   type= "text "   name= "sfd "> </td>
</tr>
</table>

------解决方案--------------------
<table width= "100% " border= "0 " cellpadding= "0 " cellspacing= "1 ">
<tr>
<td > <input name= "Yearsffd2 " onkeyup= "c() "> </td>
<td > <input name= "Yearsffd " onkeyup= "c() "> </td>
<td > <input type= "text " name= "sfd "> </td>
</tr>
</table>
<script>
o1 = document.getElementsByName( "Yearsffd2 ")[0];
o2 = document.getElementsByName( "Yearsffd ")[0];
o = document.getElementsByName( "sfd ")[0];
function c()
{
v1 = o1.value ? o1.value : 0;
v2 = o2.value ? o2.value : 0;
o.value = parseInt(v1) + parseInt(v2);
}
</script>
------解决方案--------------------
感觉用parseFloat比较合适吧,万一出浮点数,然后需不需要考虑用Math.round进行四舍五入之类的算法?