TextBox:(多个TextBox求和问题)

项目单价人次天数小计说明
住宿     
交通     
交际     
其他     
合计 

偶然看到一张出差申请单,闲着没事,就做了其中的一部分,算是练习吧!嘿嘿。。。

<script type="text/javascript" language="javascript">

        //禁止输入非数字
         function JHshNumberText() {
             if (!(((window.event.keyCode >= 48) && (window.event.keyCode <= 57))
        || (window.event.keyCode == 13) || (window.event.keyCode == 46)
        || (window.event.keyCode == 45))) {
                 window.event.keyCode = 0;
             }
         }
         //小计
         function getSum(_obj) {
             var tr = _obj.parentNode.parentNode;
             var price = tr.cells[1].firstChild; //单价
             var Peosernumber = tr.cells[2].firstChild;//人次
             var tb_daycounts = tr.cells[3].firstChild; //天数
             tr.cells[4].firstChild.value = (price.value == "" ? 0 : price.value) * (Peosernumber.value == "" ? 0 : Peosernumber.value) * (tb_daycounts.value == "" ? 0 : tb_daycounts.value);
            
         }

       //合计

         function getAllSum() {
             var sum1 = document.getElementById("tb_count");
             var sum2 = document.getElementById("tb_count0");
             var sum3 = document.getElementById("tb_count1");
             var sum4 = document.getElementById("tb_count2");
             document.getElementById("tb_totalCount").value =
              (sum1.value == "" ? 0 : parseInt(sum1.value)) + (sum2.value == "" ? 0 : parseInt(sum2.value)) + (sum3.value == "" ? 0 : parseInt(sum3.value)) + (sum4.value == "" ? 0 : parseInt(sum4.value));
         }
    </script>

 

 <table border="1" cellpadding="0" cellspacing="0" width="100%">
             <tr>
               <td class="style7">项目</td>
               <td>单价</td>
               <td>人次</td>
               <td class="style3">天数</td>
               <td>小计</td>
               <td>说明</td>
             </tr>
               <tr>
               <td class="style7">住宿</td>
               <td>
                 <asp:TextBox ID="tb_cost" runat="server" Width="80px" tip="设置单价" onKeyPress="JHshNumberText()" οnblur="getSum(this)">
                 </asp:TextBox>
                   </td>
               <td>
                 <asp:TextBox ID="tb_Peosernumber" runat="server" Width="80px" tip="设置人次" onKeyPress="JHshNumberText()" οnblur="getSum(this)">
                 </asp:TextBox>
                   </td>
               <td class="style3">
                 <asp:TextBox ID="tb_daycounts" runat="server" Width="80px" tip="设置天数" onKeyPress="JHshNumberText()" οnblur="getSum(this)">
                 </asp:TextBox>
                   </td>
               <td>
                 <asp:TextBox ID="tb_count" runat="server" Width="80px" onKeyPress="JHshNumberText()" οnblur="getSum(this)">
                 </asp:TextBox>
                   </td>
               <td>
                 <asp:TextBox ID="tb_remark" runat="server" Width="110px" tip="备注或说明"></asp:TextBox>
                   </td>
             </tr>
              <tr>
               <td class="style8">交通</td>
               <td class="style9">
                 <asp:TextBox ID="tb_cost0" runat="server" Width="80px" onKeyPress="JHshNumberText()" οnblur="getSum(this)"></asp:TextBox>
                   </td>
               <td class="style9">
                 <asp:TextBox ID="tb_Peosernumber0" runat="server" Width="80px" onKeyPress="JHshNumberText()" οnblur="getSum(this)"></asp:TextBox>
                   </td>
               <td class="style10">
                 <asp:TextBox ID="tb_daycounts0" runat="server" Width="80px" onKeyPress="JHshNumberText()" οnblur="getSum(this)"></asp:TextBox>
                   </td>
               <td class="style9">
                 <asp:TextBox ID="tb_count0" runat="server" Width="80px"></asp:TextBox>
                   </td>
               <td class="style9">
                 <asp:TextBox ID="tb_remark0" runat="server" Width="110px" onKeyPress="JHshNumberText()" οnblur="getSum(this)"></asp:TextBox>
                   </td>
             </tr>
             <tr>
               <td class="style7">交际</td>
               <td>
                 <asp:TextBox ID="tb_cost1" runat="server" Width="80px" onKeyPress="JHshNumberText()" οnblur="getSum(this)"></asp:TextBox>
                   </td>
               <td>
                 <asp:TextBox ID="tb_Peosernumber1" runat="server" Width="80px" onKeyPress="JHshNumberText()" οnblur="getSum(this)"></asp:TextBox>
                   </td>
               <td class="style3">
                 <asp:TextBox ID="tb_daycounts1" runat="server" Width="80px" onKeyPress="JHshNumberText()" οnblur="getSum(this)"></asp:TextBox>
                   </td>
               <td>
                 <asp:TextBox ID="tb_count1" runat="server" Width="80px" onKeyPress="JHshNumberText()" οnblur="getSum(this)"></asp:TextBox>
                   </td>
               <td>
                 <asp:TextBox ID="tb_remark1" runat="server" Width="110px" onKeyPress="JHshNumberText()" οnblur="getSum(this)"></asp:TextBox>
                   </td>
             </tr>
             <tr>
               <td class="style7">其他</td>
               <td>
                 <asp:TextBox ID="tb_cost3" runat="server" Width="80px" onKeyPress="JHshNumberText()" οnblur="getSum(this)"></asp:TextBox>
                   </td>
               <td>
                 <asp:TextBox ID="tb_cost4" runat="server" Width="80px" onKeyPress="JHshNumberText()" οnblur="getSum(this)"></asp:TextBox>
                   </td>
               <td class="style3">
                 <asp:TextBox ID="tb_daycounts2" runat="server" Width="80px" onKeyPress="JHshNumberText()" οnblur="getSum(this)"></asp:TextBox>
                   </td>
               <td>
                 <asp:TextBox ID="tb_count2" runat="server" Width="80px" onKeyPress="JHshNumberText()" οnblur="getSum(this)"></asp:TextBox>
                   </td>
               <td>
                 <asp:TextBox ID="tb_remark2" runat="server" Width="110px" onKeyPress="JHshNumberText()" οnblur="getSum(this)"></asp:TextBox>
                   </td>
             </tr>
             <tr>
               <td class="style7">合计</td>
               <td colspan="5" align="left">
                   <asp:TextBox ID="tb_totalCount" runat="server" Width="170px"
                   onKeyPress="JHshNumberText()" οnfοcus="getAllSum()"></asp:TextBox>
                 </td>
             </tr>
           </table>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值