window.onload = function startCalc(){
  interval = setInterval("calc();sum();",1);
}
改成
window.onload = function startCalc(){
  interval = setTimeout("calc();sum();",10);
}
这样看看

解决方案 »

  1.   

    interval = setInterval("calc();sum();",1);这句话是非常占CPU的,请换另外一种方式!
      

  2.   

    如果希望像原来那样一直计算可以这样改
    window.onload = function startCalc(){
      interval = setInterval("calc();sum();",100);
    }
    把时间改大
      

  3.   

    改成用事件触发啊,非要用setInterval啊
      

  4.   

    不就自动计算嘛。需要用到setInterval吗?
      

  5.   

    你用键盘事件不好啊。onkeypress.onkeydown.onkeyup 都比setInterval好使阿。
      

  6.   

    比较变态,间隔时间竟然只有 1 毫秒, 改成事件触发吧. onkeyup onblur 等都可以
      

  7.   

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>+&nbsp; =</title>
    </head>
    <script type="text/javascript">
    window.onload = function startCalc(){
      interval = setInterval("calc();sum();",1);
    }
    function calc(){
      //alert("yy");
      fi= document.getElementsByName("firstBox");
      //alert(fi[0].value)
      se = document.getElementsByName("secondBox");
      thi = document.getElementsByName("thirdBox");
      for (i=0;i<fi.length;i++){
        thi[i].value=((fi[i].value)*1)+((se[i].value)*1);
      }
      //two = document.autoSumForm.secondBox.value; 
      //document.autoSumForm.thirdBox.value = (one * 1) + (two * 1);
    }
    function stopCalc(){
      clearInterval(interval);
    }
    function app(){
      o=document.getElementById("aa");
      str=o.innerHTML;
      //alert(str);
      o1=document.getElementById("bb"); 
      //alert(o1.html);
      o1.innerHTML= o1.innerHTML+"</br>"+str;
    }function sum(){//累加
      thi = document.getElementsByName("thirdBox");
      tot = document.getElementsByName('totalBox');
      tot[0].value="0";
      for(i=0;i<thi.length;i++){
        if(thi[i].value!=''){
          tot[0].value=tot[0].value*1+thi[i].value*1;
    }
      }
    }
    </script>
    <form name="autoSumForm" id="form1">
    <div id="aa">
    <input type=text name="firstBox" value="5" onpropertychange="sum();" > + 
    <input type=text name="secondBox" value="" onpropertychange="sum();"> = 
    <input type=text name="thirdBox"><br></div>
    <input type=text name="firstBox" value="" onpropertychange="sum();"> + 
    <input type=text name="secondBox" value="" onpropertychange="sum();"> = 
    <input type=text name="thirdBox"><br>
    <div id="bb"><input type=text name="firstBox" value="" onpropertychange="sum();"> + 
    <input type=text name="secondBox" value="" onpropertychange="sum();"> = 
    <input type=text name="thirdBox"></div>
    <input type="button" value="append" onclick="app();sum()"><span style="margin-left:262px">sum:<input type="text" name="totalBox" value="0"></span>
    </form>
    <p> </p>
    </body>
    </html>
      

  8.   

    interval = setInterval("calc();sum();",1); 间隔时间太短了
      

  9.   

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>+&nbsp; =</title>
    </head>
    <script type="text/javascript">
    window.onload = function startCalc(){
    sum();
      //interval = setInterval("",1);
    }
    function calc(){
      //alert("yy");
      fi= document.getElementsByName("firstBox");
      //alert(fi[0].value)
      se = document.getElementsByName("secondBox");
      thi = document.getElementsByName("thirdBox");
      for (i=0;i<fi.length;i++){
        thi[i].value=((fi[i].value)*1)+((se[i].value)*1);
      }
      //two = document.autoSumForm.secondBox.value; 
      //document.autoSumForm.thirdBox.value = (one * 1) + (two * 1);
    }
    function stopCalc(){
      clearInterval(interval);
    }
    function app(){
      o=document.getElementById("aa");
      str=o.innerHTML;
      //alert(str);
      o1=document.getElementById("bb"); 
      //alert(o1.html);
      o1.innerHTML= o1.innerHTML+"</br>"+str;
    }function sum(){//累加
    calc();
      thi = document.getElementsByName("thirdBox");
      tot = document.getElementsByName('totalBox');
      tot[0].value="0";
      for(i=0;i<thi.length;i++){
        if(thi[i].value!=''){
          tot[0].value=tot[0].value*1+thi[i].value*1;
    }
      }
    }
    </script>
    <form name="autoSumForm" id="form1">
    <div id="aa">
    <input type=text name="firstBox" value="5" onpropertychange="sum();" > + 
    <input type=text name="secondBox" value="" onpropertychange="sum();"> = 
    <input type=text name="thirdBox"><br></div>
    <input type=text name="firstBox" value="" onpropertychange="sum();"> + 
    <input type=text name="secondBox" value="" onpropertychange="sum();"> = 
    <input type=text name="thirdBox"><br>
    <div id="bb"><input type=text name="firstBox" value="" onpropertychange="sum();"> + 
    <input type=text name="secondBox" value="" onpropertychange="sum();"> = 
    <input type=text name="thirdBox"></div>
    <input type="button" value="append" onclick="app();sum()"><span style="margin-left:262px">sum:<input type="text" name="totalBox" value="0"></span>
    </form>
    <p> </p>
    </body>
    </html>