<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<script language="JavaScript">
<!--
function Calc()
{
var sum;
var stm;
var i; sum = 0;
for(i = 0; i < 4; i++)
{
stm = "sum += 1 * form1.input" + i + ".value";
eval(stm);
}
form1.sum.value = sum;
}
//-->
</script>
</head><body>
<form name=form1>
<input type=text name=input0 value=1><br>
<input type=text name=input1 value=2><br>
<input type=text name=input2 value=3><br>
<input type=text name=input3 value=4><br>
<input type=text name=sum><br>
<input type=button value="Calc" onclick="Calc()">
</form>
</body>
</html>

解决方案 »

  1.   

    <script language="Javascript">
    function test(){
    var i = 0,sum=0;
    var count = document.all.text1.length;
    for(i=0; i<count; i++){
    sum += eval(document.all.text1[i].value);
    }
    document.all.sum.value = sum;
    }
    </script>
    <br>
    <input type=text name=text1 id=text1 value=1><br>
    <input type=text name=text1 id=text1 value=2><br>
    <input type=text name=text1 id=text1 value=3><br>
    <input type=text name=text1 id=text1 value=4><br>
    <input type=text name=sum id=sum><br>
    <input type=button value="test" onclick="test();">
    ok??
      

  2.   

     感谢edyang(愚顽),supersonics(落叶狂风)的帮助,问题已解决。
     感谢net_lover(孟子E章),dhwan(大海湾)的关注,还请多指教。