每一个文本框里边都写上一个相同的onchange或者onblur事件,这样每次输入完了,都可以去做一边求和的操作,这样每次都会将合计值放到你的合计框里边。不就可以了吗?

解决方案 »

  1.   

    哦,忘了说了,我是用onKeyDown和onBlur来触发那个function的,但是onBlur好象不起作用.
      

  2.   

    andymu077(明治佐玛戒--秀曼) 谢谢,onChange可以了,再请问一下,当鼠标点中一个输入框后,怎么能让里面的内容全选.再次感谢!!
      

  3.   

    我觉得你不应该用onKeyDown,最好使用一下onKeyUp来做,我下边试着做了一个:
    <html>
    <head>
    <title>Untitled</title>
    <Script language="javascript">
    <!--
    function fncSum(){
    var obj=document.all;
    var temp=0
    for (i=0;i<obj.txt.length;i++){
    temp=Number(temp)+Number(obj.txt(i).value);
    }
    obj.txtSum.value=Number(temp);}//-->
    </Script>
    </head>
    <body>
    <form>
    <input type="text" name="txt" value="" onKeyUp="fncSum()"><br>
    <input type="text" name="txt" value="" onKeyUp="fncSum()"><br>
    <input type="text" name="txt" value="" onKeyUp="fncSum()"><br>
    <input type="text" name="txt" value="" onKeyUp="fncSum()"><br>
    <input type="text" name="txt" value="" onKeyUp="fncSum()"><br>
    <input type="text" name="txt" value="" onKeyUp="fncSum()"><br>
    <input type="text" name="txt" value="" onKeyUp="fncSum()"><br>
    <input type="text" name="txt" value="" onKeyUp="fncSum()"><br>
    <input type="text" name="txt" value="" onKeyUp="fncSum()"><br>
    <center>
    SUM:<input type="text" name="txtSum" value="0">
    </center>
    </form>
    </body>
    </html>
      

  4.   

    <html>
    <head>
    <title>Untitled</title>
    <Script language="javascript">
    <!--
    function fncSum(){
    var obj=document.all;
    var temp=0
    for (i=0;i<obj.txt.length;i++){
    temp=parseFloat(temp)+parseFloat(obj.txt(i).value);
    }
    obj.txtSum.value=parseFloat(temp);}function fncSelect(obj){
    //window.event.shiftKey=true;
    //alert(window.event.shiftKey)
    this.select();
    }//-->
    </Script>
    </head>
    <body>
    <form>
    <input type="text" name="txt" value="" onKeyUp="fncSum()" onclick="this.select();"><br>
    <input type="text" name="txt" value="" onKeyUp="fncSum()" onclick="this.select();"><br>
    <input type="text" name="txt" value="" onKeyUp="fncSum()" onclick="this.select();"><br>
    <input type="text" name="txt" value="" onKeyUp="fncSum()" onclick="this.select();"><br>
    <input type="text" name="txt" value="" onKeyUp="fncSum()" onclick="this.select();"><br>
    <input type="text" name="txt" value="" onKeyUp="fncSum()" onclick="this.select();"><br>
    <input type="text" name="txt" value="" onKeyUp="fncSum()" onclick="this.select();"><br>
    <input type="text" name="txt" value="" onKeyUp="fncSum()" onclick="this.select();"><br>
    <input type="text" name="txt" value="" onKeyUp="fncSum()" onclick="this.select();"><br>
    <center>
    SUM:<input type="text" name="txtSum" value="0">
    </center>
    </form>
    </body>
    </html>
      

  5.   

    andymu077(明治佐玛戒--秀曼) 的可以了.thk
     我还用的onkeydown,onkeyup的话敲回车不起作用了,我还是要保留回车相当于敲了个tab
    结帖.
      

  6.   

    一个比较麻烦的办法:
    <html>
    <head>
    <title>Untitled</title>
    <Script language="javascript">
    <!--
    function fncSum(No){
    var obj=document.all;
    var temp=0
    if (window.event.keyCode==13){
    for (i=0;i<obj.txt.length;i++){
    temp=Number(temp)+Number(obj.txt(i).value);
    if (No==i-1){
    obj.txt(i).focus();
    }
    }
    }
    obj.txtSum.value=Number(temp);
    }function fncSelect(obj){
    //window.event.shiftKey=true;
    //alert(window.event.shiftKey)
    this.select();
    }//-->
    </Script>
    </head>
    <body>
    <form>
    <input type="text" name="txt" value="" onKeyUp="fncSum(0)" onclick="this.select();"><br>
    <input type="text" name="txt" value="" onKeyUp="fncSum(1)" onclick="this.select();"><br>
    <input type="text" name="txt" value="" onKeyUp="fncSum(2)" onclick="this.select();"><br>
    <input type="text" name="txt" value="" onKeyUp="fncSum(3)" onclick="this.select();"><br>
    <input type="text" name="txt" value="" onKeyUp="fncSum(4)" onclick="this.select();"><br>
    <input type="text" name="txt" value="" onKeyUp="fncSum(5)" onclick="this.select();"><br>
    <input type="text" name="txt" value="" onKeyUp="fncSum(6)" onclick="this.select();"><br>
    <input type="text" name="txt" value="" onKeyUp="fncSum(7)" onclick="this.select();"><br>
    <input type="text" name="txt" value="" onKeyUp="fncSum(8)" onclick="this.select();"><br>
    <center>
    SUM:<input type="text" name="txtSum" value="0">
    </center>
    </form>
    </body>
    </html>