TextBox:(多個TextBox求和問題)

來源:互聯網
上載者:User
項目 單價 人次 天數 小計 說明
住宿          
交通          
交際          
其他          
合計  

偶然看到一張出差申請單,閑著沒事,就做了其中的一部分,算是練習吧!嘿嘿。。。

<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()" onblur="getSum(this)">
                 </asp:TextBox>
                   </td>
               <td>
                 <asp:TextBox ID="tb_Peosernumber" runat="server" Width="80px" tip="設定人次" onKeyPress="JHshNumberText()" onblur="getSum(this)">
                 </asp:TextBox>
                   </td>
               <td class="style3">
                 <asp:TextBox ID="tb_daycounts" runat="server" Width="80px" tip="設定天數" onKeyPress="JHshNumberText()" onblur="getSum(this)">
                 </asp:TextBox>
                   </td>
               <td>
                 <asp:TextBox ID="tb_count" runat="server" Width="80px" onKeyPress="JHshNumberText()" onblur="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()" onblur="getSum(this)"></asp:TextBox>
                   </td>
               <td class="style9">
                 <asp:TextBox ID="tb_Peosernumber0" runat="server" Width="80px" onKeyPress="JHshNumberText()" onblur="getSum(this)"></asp:TextBox>
                   </td>
               <td class="style10">
                 <asp:TextBox ID="tb_daycounts0" runat="server" Width="80px" onKeyPress="JHshNumberText()" onblur="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()" onblur="getSum(this)"></asp:TextBox>
                   </td>
             </tr>
             <tr>
               <td class="style7">交際</td>
               <td>
                 <asp:TextBox ID="tb_cost1" runat="server" Width="80px" onKeyPress="JHshNumberText()" onblur="getSum(this)"></asp:TextBox>
                   </td>
               <td>
                 <asp:TextBox ID="tb_Peosernumber1" runat="server" Width="80px" onKeyPress="JHshNumberText()" onblur="getSum(this)"></asp:TextBox>
                   </td>
               <td class="style3">
                 <asp:TextBox ID="tb_daycounts1" runat="server" Width="80px" onKeyPress="JHshNumberText()" onblur="getSum(this)"></asp:TextBox>
                   </td>
               <td>
                 <asp:TextBox ID="tb_count1" runat="server" Width="80px" onKeyPress="JHshNumberText()" onblur="getSum(this)"></asp:TextBox>
                   </td>
               <td>
                 <asp:TextBox ID="tb_remark1" runat="server" Width="110px" onKeyPress="JHshNumberText()" onblur="getSum(this)"></asp:TextBox>
                   </td>
             </tr>
             <tr>
               <td class="style7">其他</td>
               <td>
                 <asp:TextBox ID="tb_cost3" runat="server" Width="80px" onKeyPress="JHshNumberText()" onblur="getSum(this)"></asp:TextBox>
                   </td>
               <td>
                 <asp:TextBox ID="tb_cost4" runat="server" Width="80px" onKeyPress="JHshNumberText()" onblur="getSum(this)"></asp:TextBox>
                   </td>
               <td class="style3">
                 <asp:TextBox ID="tb_daycounts2" runat="server" Width="80px" onKeyPress="JHshNumberText()" onblur="getSum(this)"></asp:TextBox>
                   </td>
               <td>
                 <asp:TextBox ID="tb_count2" runat="server" Width="80px" onKeyPress="JHshNumberText()" onblur="getSum(this)"></asp:TextBox>
                   </td>
               <td>
                 <asp:TextBox ID="tb_remark2" runat="server" Width="110px" onKeyPress="JHshNumberText()" onblur="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()" onfocus="getAllSum()"></asp:TextBox>
                 </td>
             </tr>
           </table>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.