TextBox文本中的数值相加(JavaScript)

<script type="text/javascript">
                                  function Sumtxt(obj)
                                        {
                                            var strtxt1 =obj.value;
                                            var objtxt3 = document.getElementById("txtTotal");
                                            var tot=parseInt(objtxt3.value);
                                            tot += parseInt(strtxt1);
                                            objtxt3.value=tot;
                                        } 
</script>
HTML代码:
 <asp:TextBox ID="txtArea" runat="server" Width="40px" onblur="Sumtxt(this)"></asp:TextBox>
 <asp:TextBox ID="txtTotal" runat="server" Width="40px" Text="0"></asp:TextBox>
对每一个textbox控件添加:onblur="Sumtxt(this)",在结果文本框中初始化数字‘0’
posted @ 2009-08-16 12:33  雨晴空  阅读(1426)  评论(0编辑  收藏  举报