jquery 实现文本框自动求和!!

解决方案 »

  1.   

    这样吗?
    <!DOCTYPE html>
    <html>
    <head>
    <title>jQuery</title>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
    </head><body>
    </body>
    <input type="text" id="txt1" /> +
    <input type="text" id="txt2" /> =
    <input type="text" id="txt3" />
    <script type="text/javascript">
    $(function(){
        var func = function(){
            var val = parseFloat($('#txt1').val()) + parseFloat($('#txt2').val());
            $('#txt3').val(val);
        };
        $('#txt1').change(func);
        $('#txt2').change(func);
    });
    </script>
    </html>
      

  2.   

    修改下<script type="text/javascript">
    $(function(){
        var func = function(){
            var val = parseFloat($('#txt1').val()) + parseFloat($('#txt2').val());
            $('#txt3').val(val);
        };
        $('#txt1,#txt2').change(func).keyup(func);
    });
    </script>
      

  3.   

    引用楼主 skydemo 的回复:
    jquery 实现文本框自动求和!!首先你就没有说清楚,   
      

  4.   

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="_601_Default4" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>无标题页</title>    <script src="../jquery-1.4.2.min.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(function(){
                $("input[name='txt']").blur(function(){
                    var count_1 = $.trim($("#txtCount1").val());
                    var count_2 = $.trim($("#txtCount2").val());
                    
                    if(count_1 != "" && count_2 != "")
                    {
                        $("#txtTotal").val(parseInt(count_1)+parseInt(count_2));
                    }
                });
            });
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <input id="txtCount1" name="txt" type="text" /> +
            <input id="txtCount2" name="txt" type="text" /> =
            <input id="txtTotal" name="txt" type="text" readonly="readonly" />
        </div>
        </form>
    </body>
    </html>
      

  5.   

    textbox事件来激发js事件 获取输入的值 累加
      

  6.   

    js写写就可以了么,干嘛用jq
    <head runat="server">
        <title>无标题页</title>
        <script language="javascript" type="text/javascript">
        function tot()
        {
           var aa=document.getElementById("Text1")
           var bb=document.getElementById("Text2")
           var cc=document.getElementById("Text3")
           if(aa.value!=""&&bb.value!="")
           {
           cc.value=parseInt(aa.value)+parseInt(bb.value)
           }
        }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <input id="Text1" type="text" onkeyup="tot()"/>+<input id="Text2" type="text" onkeyup="tot()"/>=<input id="Text3" type="text" readonly="readonly"/>
        </div>
        </form>
    </body>