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]);
}
}
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]);
}
}
<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>