比如 我有两个文本框 当第二个文本框输入一个数字时  这两个文本框的值加起来赋值给lable   我不要点击按钮实现  也不要Change事件  因为这样只有失去焦点时才会计算  ,有没有其他方法呢?求助!求助!求助!求助!求助!求助!

解决方案 »

  1.   

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>无标题页</title>
        <script type="text/javascript">
        function sum() {
            var t1 = document.getElementById("TextBox1");
            var t2 = document.getElementById("TextBox2");
            if (isNaN(t1.value)) {
                t1.value = "0";
            }
            if (isNaN(t2.value)) {
                t2.value = "0";
            }
            document.getElementById("Label1").innerHTML = parseInt(t1.value) + parseInt(t2.value);
        }
        </script>
    </head><body>
        <form id="form1" runat="server">
        <div>
            <asp:TextBox ID="TextBox1" runat="server" Text="0" onkeyup  ="sum()"></asp:TextBox>
            <asp:TextBox ID="TextBox2" runat="server" Text="0" onkeyup  ="sum()" ></asp:TextBox>
             <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
             
            <input id="Text1" type="text"  />    </div>
        </form>
    </body>
    </html>
      

  2.   

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>无标题页</title>
        <script type="text/javascript">
        function sum() {
            var t1 = document.getElementById("TextBox1");
            var t2 = document.getElementById("TextBox2");
            if (isNaN(t1.value)) {
                t1.value = "0";
            }
            if (isNaN(t2.value)) {
                t2.value = "0";
            }
            document.getElementById("Label1").innerHTML = parseInt(t1.value) + parseInt(t2.value);
        }
        </script>
    </head><body>
        <form id="form1" runat="server">
        <div>
            <asp:TextBox ID="TextBox1" runat="server" Text="0" onkeyup  ="sum()"></asp:TextBox>
            <asp:TextBox ID="TextBox2" runat="server" Text="0" onkeyup  ="sum()" ></asp:TextBox>
             <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        </div>
        </form>
    </body>
    </html>