我有一个如下的javascript函数:
function calculateBill(id,price)
{
var qty = document.getElementById('qty_'+id).value;
var cur_value =qty*price;
var frm_lngth = document.getElementById('bnfsendgoods').length;
var fld_length1 = Number(frm_lngth) - 10;
var counter = document.getElementById('cntr').value;
var fld_length = (Number(fld_length1)) / (Number(counter));
fld_length = Number(fld_length);
var temp_total = 0;
alert(fld_length);
for(var i = 1; i<=fld_length; i++)
{
if( i != id )
{
alert('qty_'+i); //line 301,alerts only qty_1
var temp_q = document.getElementById('qty_'+i).value;
var temp_p = document.getElementById('ret_price_'+i).value; //Line 308
var temp_total1 = temp_q*temp_p;
temp_total = Number(temp_total) + Number(temp_total1);
}
}
var final_total = Number(cur_value) + Number(temp_total);
document.getElementById('total').value = final_total;
}
在第 301 行,alert(fld_length);
警报 8 。如果假设id = 3
,根据我的逻辑,它应该像qty_1
, qty_2
, qty_4
, qty_5
,qty_6
等等一样提醒。但它只会发出警报 qty_1
。怎么了?