window.onload = function(){计算语句}

解决方案 »

  1.   

    这样好了呀:
    <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()",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" onFocus="startCalc();" onBlur="stopCalc();sum();"> + 
    <input type=text name="secondBox" value="" onFocus="startCalc();" onBlur="stopCalc();sum();"> = 
    <input type=text name="thirdBox"><br></div>
    <input type=text name="firstBox" value="" onFocus="startCalc();" onBlur="stopCalc();sum();"> + 
    <input type=text name="secondBox" value="" onFocus="startCalc();" onBlur="stopCalc();sum();"> = 
    <input type=text name="thirdBox"><br>
    <div id="bb"><input type=text name="firstBox" value="" onFocus="startCalc();" onBlur="stopCalc();sum();"> + 
    <input type=text name="secondBox" value="" onFocus="startCalc();" onBlur="stopCalc();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>
      

  2.   

    这样好了,下面那个 sum方法也自动计算呢?我在sum方法前也加window.onload = 计算不出sum方法.
      

  3.   

    window.onload = function startCalc(){
      interval = setInterval("calc()",1); //上面的代码要先通过这个方法算出第三文本框的值
      interval2 = setInterval("sum()",1) //sum()函数只是计算所有第三文本框的总和
     //这样才能得到你想要的结果
    }
      

  4.   

    <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" onFocus="startCalc();" onBlur="stopCalc();sum();"> + 
    <input type=text name="secondBox" value="" onFocus="startCalc();" onBlur="stopCalc();sum();"> = 
    <input type=text name="thirdBox"><br></div>
    <input type=text name="firstBox" value="" onFocus="startCalc();" onBlur="stopCalc();sum();"> + 
    <input type=text name="secondBox" value="" onFocus="startCalc();" onBlur="stopCalc();sum();"> = 
    <input type=text name="thirdBox"><br>
    <div id="bb"><input type=text name="firstBox" value="" onFocus="startCalc();" onBlur="stopCalc();sum();"> + 
    <input type=text name="secondBox" value="" onFocus="startCalc();" onBlur="stopCalc();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>
      

  5.   

    我的下面这段代码  运行后占CPU太高  估计是JAVASCRIPT在页面运行时占CPU大,而且我的JAVASCRIPT代码写的不好,谁帮看看,解决了给60分,提正确意见给30分<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <%!public String IsoConvertGc(String insert) { String outstr; try { if (insert == null || insert.trim().length() == 0) { return insert; } outstr = new String(insert.getBytes("iso-8859-1"),"gb2312"); } catch (Exception e) { outstr = null; } return outstr; }%>
    <%!public String IsoConvertGb(String insert) { String outstr; try { if (insert == null || insert.trim().length() == 0) { return insert; } outstr = new String(insert.getBytes("gb2312"), "iso-8859-1"); } catch (Exception e) { outstr = null; } return outstr; }%>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <link href="css1/Style1.css" type="text/css" rel="stylesheet">
    <title>工作计划填写</title>
    <style type="text/css">
    <!--
    .style6 {color: #FF0000}
    -->
    </style>
    </head>
    <script type="text/javascript">
    window.onload =  function startCalc(){
      interval = setInterval("calc();sum2();sum3();sum4();sum();sum1();onBlur;",1);}
    function calc(){
      //alert("yy");
      f1= document.getElementsByName("zipingg");
      f6= document.getElementsByName("manfeng");
      f2 = document.getElementsByName("zongheg");
      f3 = document.getElementsByName("zonglig");
      f4 = document.getElementsByName("lingdaog");
      f5 = document.getElementsByName("defeng");
      f7 = document.getElementsByName("zongdefen");
      
      y1= document.getElementsByName("zipingy");
      y6= document.getElementsByName("manfeny");
      y3 = document.getElementsByName("zongliy");
      y4 = document.getElementsByName("lingdaoy");
      y5 = document.getElementsByName("defeny");
      
      k1= document.getElementsByName("zipingf");
      k3 = document.getElementsByName("zonglif");
      k4 = document.getElementsByName("lingdaof");
      k5 = document.getElementsByName("defenf");
      
      g1= document.getElementsByName("zonghek");
      g3 = document.getElementsByName("zonglik");
      g4 = document.getElementsByName("lingdaok");
      g5 = document.getElementsByName("defenk");
      for (i=0;i<f1.length;i++){
        f5[i].value=(f6[i].value)*(((f1[i].value)*0.05)+((f2[i].value)*0.25)+((f3[i].value)*0.5)+((f4[i].value)*0.2))/5;
      }
        for (i=0;i<y1.length;i++){
        y5[i].value=(y6[i].value)*(((y1[i].value)*0.1)+((y3[i].value)*0.5)+((y4[i].value)*0.4))/5;
      }
      for (i=0;i<k1.length;i++){
        k5[i].value=-100*(((k1[i].value)*0.1)+((k3[i].value)*0.45)+((k4[i].value)*0.45))/5;
      }
    for (i=0;i<g1.length;i++){
        g5[i].value=((g1[i].value)*1)+((g3[i].value)*1)+((g4[i].value)*1);
      }
    }function stopCalc(){
      clearInterval(interval);
    }function sum2(){//加总
      thi = document.getElementsByName("defeng");
      tot = document.getElementsByName('defengz');
      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;
    }
      }
    }
    function sum3(){//加总
      thi = document.getElementsByName("defeny");
      tot = document.getElementsByName('defenyz');
      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;
    }
      }
    }
    function sum4(){//加总
      thi = document.getElementsByName("defenk");
      tot = document.getElementsByName('defenkz');
      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;
    }
      }
    }
     
       function   onBlur()   
      {   
            with(document.autoSumForm)   
            {   
                  var   n   =   0;   
                  if   (defengz.value   !=   "")   n   +=   parseFloat(defengz.value)*0.2;   //parseInt   
                  if   (defenyz.value   !=   "")   n   +=   parseFloat(defenyz.value)*0.8;   
                  if   (defenkz.value   !=   "")   n   +=   parseFloat(defenkz.value); 
      if   (defenf.value   !=   "")   n   +=   parseFloat(defenf.value);  
                 
                  zongdefen.value   =   n;   fen.value   =   n;
            }   
      }   
      </script> 
    <body>
    <br><br><br><% java.util.Date  dt = new java.util.Date(); %>
     <%
    request.setCharacterEncoding("gb2312");
    Connection conn = null;    String hostName       = "";    String portNumber     = "1521";    String databaseSID    = "";     String userName       = "";    String password       = ""; String url = "jdbc:oracle:thin:@"+hostName+":"+portNumber+":"+databaseSID;   
      System.out.println(url);
    Class.forName("oracle.jdbc.driver.OracleDriver");
    conn = DriverManager.getConnection(url,userName,password);
    Statement statement=conn.createStatement();Statement statement1=conn.createStatement();Statement statement2=conn.createStatement();Statement statement3=conn.createStatement();Statement statement4=conn.createStatement();Statement statement5=conn.createStatement();Statement statement6=conn.createStatement();
    String xingming,nian,yue,xingming1;
    nian=request.getParameter("nian");yue=request.getParameter("yue");xingming1=request.getParameter("xingming");
    xingming=IsoConvertGb(xingming1);
    ResultSet rs =statement.executeQuery("select * from kaopingbiao where tianxie='"+xingming+"' and nian='"+nian+"' and yue='"+yue+"'  and  fenlei='1'    order by xuhao");
      

  6.   

    ResultSet rs1 =statement1.executeQuery("select * from kaopingbiao where tianxie='"+xingming+"' and nian='"+nian+"' and yue='"+yue+"' and  fenlei='2' order  by  xuhao   ");
    ResultSet rs2 =statement2.executeQuery("select * from kaopingbiao where tianxie='"+xingming+"' and nian='"+nian+"' and yue='"+yue+"' and  fenlei='3'  order  by  xuhao  ");
    ResultSet rs3 =statement3.executeQuery("select * from kaopingbiao where tianxie='"+xingming+"' and nian='"+nian+"' and yue='"+yue+"' and  fenlei='4' order  by  xuhao  ");
    ResultSet rs4 =statement4.executeQuery("select * from kaopingfen where tianxie='"+xingming+"' and nian='"+nian+"' and yue='"+yue+"'  ");
    ResultSet rs5 =statement5.executeQuery("select * from kaoyijian where tianxie='"+xingming+"' and nian='"+nian+"' and yue='"+yue+"'   ");
    ResultSet rs6 =statement6.executeQuery("select   MANAGER_NAME from zhuce  order by  quanxian  ");
    %>
    <form action="zonghe.jsp" name="" method="post"> 
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;姓名:  <select name="xingming" id="xingming">
                <%
    request.setCharacterEncoding("GBK");
    while (rs6.next())
    {
       %>
        <option value="<%=IsoConvertGc(rs6.getString("MANAGER_NAME"))%>" selected><%=IsoConvertGc(rs6.getString("MANAGER_NAME"))%></option><% } %>
      </select>
      <input name="nian" type="text" id="nian" value="<%=String.valueOf(1900+dt.getYear())%>" size="10">

    <input name="yue" type="text" id="yue" onmouseover='this.focus()' value="<%=String.valueOf(1+dt.getMonth())%>" size="10">
    月 
    <input type="submit" name="Submit3" value="查询">
      &nbsp;&nbsp;&nbsp;
    </form><form action="zhtj.jsp" name="autoSumForm" method="post">
      <table width="1000"  border="1"    bgcolor="#CCFFFF" class="greenfont">
      <tr width="973"   align="center">
                             <td height="40" colspan="10"  scope="col"><span class="style4 style2">内蒙古智博远科技开发有限责任公司考评表</span></td>
        </tr>
            <%
    request.setCharacterEncoding("GBK");
    while (rs4.next())
    {
       %>
    <tr width="973">
         <td height="40" colspan="10"  scope="col">姓名:&nbsp;
           <input name="tianxie" type="text" class="downborder" onmouseover='this.focus()' value="<%=IsoConvertGc(rs4.getString("tianxie"))%>" size="15"> 
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;部门:
           <input name="bumen" type="text" class="downborder" id="bumen" onmouseover='this.focus()' value="<%=IsoConvertGc(rs4.getString("bumen"))%>" size="15">
        &nbsp;&nbsp;时间:
        <input name="nian" type="text" class="downborder" id="nian" onmouseover='this.focus()' value="<%=IsoConvertGc(rs4.getString("nian"))%>" size="6">     
        年 &nbsp;
        <input name="yue" type="text" class="downborder" id="yue" onmouseover='this.focus()' value="<%=IsoConvertGc(rs4.getString("yue"))%>" size="6">     
        月&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;本月得分
              <input name="fen" type="text" class="downborder" readonly value="<%=IsoConvertGc(rs4.getString("fen"))%>" size="6"></td> </tr>
    <% } %>
     <tr align="center">
          <td width="43" height="57"> 考核项目 </td>
          <td width="195" > 考核内容 </td>
          <td width="197"><span class="style3 style6"> 考核情形描述(被考核员工自己填写数字或 1 , 1 代表属此情形),情形描述作为各级领导打分参考 </span></td>
          <td width="49"> 满分100分</td>
          <td width="52"> 自评分5% </td>
          <td width="49"> 综合人事评分 25 % </td>
          <td width="49"> 总经理评分 50% </td>
          <td width="50"> 领导评分 20% </td>
          <td width="52"> 得分 </td>
          <td width="200"> 备注 </td>
        </tr>
            <%
    request.setCharacterEncoding("GBK");
    while (rs.next())
    {
       %>
      <tr>
        <td height="55"><input name="xiangmug" type="text" class="downborder" id="xiangmug" onmouseover='this.focus()' value="<%=IsoConvertGc(rs.getString("xiangmu"))%>"   size="6"></td>
          <td><textarea name="contentg" cols="26" rows="3" class="downborder" id="contentg" onMouseOver='this.focus()'><%=IsoConvertGc(rs.getString("content"))%></textarea></td>
          <td><textarea name="miaoshug" cols="26" rows="3" class="downborder"  id="miaoshug" onMouseOver='this.focus()'><%=IsoConvertGc(rs.getString("miaoshu"))%></textarea></td>
          <td><input name="manfeng" type="text" class="downborder" id="manfeng" readonly  onFocus="startCalc();onBlur();" onBlur="stopCalc();sum2();sum();" value="<%=IsoConvertGc(rs.getString("manfen"))%>"   size="7" ></td>
          <td><input name="zipingg" type="text" class="downborder" readonly id="zipingg" value="<%=IsoConvertGc(rs.getString("ziping"))%>"  onFocus="startCalc();onBlur();" onBlur="stopCalc();sum2();onBlur();"  size="7"  ></td>
          <td><input name="zongheg" type="text" class="downborder" id="zongheg"  value="<%=IsoConvertGc(rs.getString("zonghe"))%>" onFocus="startCalc();onBlur();" onBlur="stopCalc();sum2();onBlur();"    size="7" ></td>
          <td><input name="zonglig" type="text" class="downborder" id="zonglig" readonly value="<%=IsoConvertGc(rs.getString("zongli"))%>"  onFocus="startCalc();onBlur();" onBlur="stopCalc();sum2();onBlur();"  size="7"></td>
          <td><input name="lingdaog" type="text" class="downborder" id="lingdaog" readonly value="<%=IsoConvertGc(rs.getString("lingdao"))%>"  onFocus="startCalc();onBlur();" onBlur="stopCalc();sum2();onBlur();" size="7"></td>
          <td><input name="defeng" type="text" class="downborder" readonly id="defeng" value="<%=IsoConvertGc(rs.getString("defen"))%>"   size="7" ></td>
          <td><textarea name="beizhug" cols="22" rows="3" class="downborder"  id="beizhug" readonly><%=IsoConvertGc(rs.getString("beizhu"))%></textarea>
            <input name="xuhaog" type="hidden" id="xuhaog" value="<%=IsoConvertGc(rs.getString("xuhao"))%>">
          </td>
      </tr> <% } %>
      </table>
      <table width="1000"  border="1"  id='DataTable1'  bgcolor="#CCFFFF" class="greenfont">
      <tr width="973"   align="center">
                             <td height="40"   scope="col" colspan="3"><span class="style3 style6">管理得分</span></td>
     <td><input name="manfengz" type="text" class="downborder" readonly id="manfengz"   size="7" ></td>
     <td height="40"   scope="col" colspan="3">管理得分=100*(自评分5%+综合评分25%+总经理评分50%+领导评分20%)</td>
     <td><input name="defengz" type="text" class="downborder" id="defengz" readonly value="0"  onblur="onBlur()" size="7"></td>
     <td>&nbsp;</td>
        </tr>
     <script type="text/javascript">
    //more javascript from http://www.smallrain.net
    <!-- Begin
    function sum(){//加总
      thi = document.getElementsByName("manfeng");
      tot = document.getElementsByName('manfengz');
      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;
    }
      }
    }
    function sum1(){//加总
      thi = document.getElementsByName("manfeny");
      tot = document.getElementsByName('manfenyz');
      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;
    }
      }
    }
    //  End -->
    </script>
    <tr align="center">
          <td width="45" height="57"> 考核项目 </td>
          <td width="195" > 考核内容 </td>
          <td width="195"><span class="style3 style6"> 考核情形描述(被考核员工自己填写数字或1,1代表属此情形),情形描述作为各级领导打分参考</span></td>
          <td width="49"> 满分100分</td>
          <td width="116"> 自评分10% </td>
          
          <td width="55"> 总经理评分 50% </td>
          <td width="54"> 领导评分 40% </td>
          <td width="52"> 得分 </td>
          <td width="181"> 备注 </td>
        </tr>
      

  7.   

        <%
    request.setCharacterEncoding("GBK");
    while (rs1.next())
    {
       %>
       <td height="55"><input name="xiangmuy" type="text" class="downborder" id="xiangmuy" onmouseover='this.focus()' value="<%=IsoConvertGc(rs1.getString("xiangmu"))%>"   size="6"></td>
          <td><textarea name="contenty" cols="26" rows="3" class="downborder" id="contenty" onMouseOver='this.focus()'><%=IsoConvertGc(rs1.getString("content"))%></textarea></td>
          <td><textarea name="miaoshuy" cols="26" rows="3" class="downborder" id="miaoshuy" onMouseOver='this.focus()'><%=IsoConvertGc(rs1.getString("miaoshu"))%></textarea></td>
          <td><input name="manfeny" type="text" class="downborder" id="manfeny" readonly onFocus="startCalc();onBlur();" onBlur="stopCalc();sum3();sum1();onBlur();" onmouseover='this.focus()' value="<%=IsoConvertGc(rs1.getString("manfen"))%>"   size="7"></td>
          <td><input name="zipingy" type="text"  readonly class="downborder" id="zipingy" value="<%=IsoConvertGc(rs1.getString("ziping"))%>"  onFocus="startCalc();onBlur();" onBlur="stopCalc();sum3();onBlur();"  size="12"  >
          <input name="xuhaoy" type="hidden" id="xuhaoy" value="<%=IsoConvertGc(rs1.getString("xuhao"))%>"></td>
          <td><input name="zongliy" type="text" readonly class="downborder" id="zongliy"  value="<%=IsoConvertGc(rs1.getString("zongli"))%>"  onFocus="startCalc();onBlur();" onBlur="stopCalc();sum3();onBlur();"  size="7"></td>
          <td><input name="lingdaoy" type="text" readonly class="downborder" id="lingdaoy"  value="<%=IsoConvertGc(rs1.getString("lingdao"))%>" onFocus="startCalc();onBlur();" onBlur="stopCalc();sum3();onBlur();"  size="7"></td>
          <td><input name="defeny" type="text" readonly class="downborder" id="defeny" value="<%=IsoConvertGc(rs1.getString("defen"))%>"   size="7" ></td>
          <td><textarea name="beizhuy" cols="24"  rows="3" class="downborder" id="beizhuy" onMouseOver='this.focus()'><%=IsoConvertGc(rs1.getString("beizhu"))%></textarea></td>
      </tr><%}%></table>
                          <table width="1000"  border="1"   bgcolor="#CCFFFF" class="greenfont">
     <tr width="973"   align="center">
                             <td height="40"   scope="col" colspan="3"><span class="style3 style6">业绩得分</span></td>
     <td><input name="manfenyz" type="text" class="downborder" id="manfenyz"   size="7" readonly></td>
     <td height="40"   scope="col" colspan="3">业绩得分=100*(自评分10%+总经理评分50%+领导评分40%)</td>
     <td><input name="defenyz" type="text" class="downborder" id="defenyz" readonly value="0" onblur="onBlur()"   size="7"></td>
     <td>&nbsp;</td>
        </tr>
    <tr align="center">
          <td width="45" height="57"> 考核项目 </td>
          <td width="195" > 考核内容 </td>
          <td width="195"><span class="style3 style6"> 考核情形描述(被考核员工自己填写数字或1,1代表属此情形),情形描述作为各级领导打分参考</span></td>
          <td width="49"> <p>满分(-100分)</p>      </td>
          <td width="116"> 自评分10% </td>
          
          <td width="55"> 总经理评分45%</td>
          <td width="54"> 领导评分45%</td>
          <td width="52"> 得分 </td>
          <td width="181"> 备注 </td>
        </tr>