<input name=w1>+
<input name=w2>+
<input name=w3>
<input type=button value="=" onclick="document.all.w4.value=parseInt(document.all.w1.value)+parseInt(document.all.w2.value)+parseInt(document.all.w3.value)">
<input name=w4>

解决方案 »

  1.   

    <html>
    <head>
    <script>
       function calc(frm){
          try{
             var result = parseFloat(frm.w1.value);
             result += parseFloat(frm.w2.value);
             result += parseFloat(frm.w3.value);
             document.all('result').value = result;
          }
          catch(e){
             alert(e.description);
          }
          
       }
    </script>
    </head>
    <body>
    <form name="form1">
       w1:<input name="w1" type="text" value=""><br>
       w2:<input name="w2" type="text" value=""><br>
       w3:<input name="w3" type="text" value=""><br>
    </form>
    结果:<input id="result" type="text" value="">
    <button onclick="calc(document.form1);">计算</button>
    </body>
    </html>
      

  2.   

    如是N个,可用eval()函数,按w1,w2,w3...规律统计,在wN显示结果.只需一个循环.