var hash = {}; //建立一个结构
hash["inputId1"] = document.formName.inputId1.value;
hash["inputId2"] = document.formName.inputId2.value; //改动多少加多少
//....var n = 0;
for(var i in hash)
{
  if(!isNaN(hash[i])
  {
    n += parseFloat(hash[i]);
  }
}

解决方案 »

  1.   

    建议用文本框控件的onBlur和onFocus事件相结合.
    <form>
    <input type="text" name="inputBox1" onBlur="reCount(this,-1)" onFocus="reCount(this,1)"> 
    .............................
    <input type="text" name="inputBoxN" onBlur="reCount(this,-1)" onFocus="reCount(this,1)">
    <input type="hidden" name="dataSum" value="0">
    </form>
    <script language="javascript">
      function reCount(obj,flag){
        var frm=obj.form;
        var dSum=parseInt(frm.dataSum.value);
        frm.dataSum.value=dSum+(flag*parseInt(obj.value));
      }
    </script>