謝謝你看這個問題。Javascript。onach class getval
我有一個問題,因爲我有幾個文本字段
它們的ID作爲跟隨
行1:
height_1,weight_1,cost_1
行31:
height_31,weight_31,cost_31
行61:
height_61,weight_61,cost_61
總計將有90行..所以,在過去的問題是
它的工作,因爲我會用下面的JavaScript來計算總的這90行。
for(i=1;i<=90;i++)
{
$('.height').each(function() {
heightTotal += Number($(this).val());
})
$("#height_row_A").html(heightTotal);
$('.weight').each(function() {
weightTotal += Number($(this).val());
})
$("#weight_row_A").html(weightTotal);
//cost is just about the same so I leave it out
}
所以,現在的問題是,在過去的90行計算在一起,並追加到這個跨度ID height_row_total和weight_row_total
但現在我需要計算第1行至30,列31至60,行61至90
各有各行上跨度在其行的頂部
跟隨這樣
行1
height_row_A,weight_row_A
行2
height_row_B,weight_row_B
行3
height_row_C,weight_row_C
如何改變我的這個
$('.height').each(function() {
heightTotal += Number($(this).val());
})
$('.weight').each(function() {
weightTotal += Number($(this).val());
})
只得到第1行至30,而不是每個值與編號高度 然後得到行31到60和61到90
我的代碼段就像這個字段的例子。 1將變更爲2在下一行,則共有30排3列
<tr><td>1</td>
<td><input class="height" type="text" maxlength="6" style="width: 40px; FONT-WEIGHT: bold; FONT-SIZE: 13px;" name="height_1" id="height_1" tabindex="1" value=""></td>
<td><input class="weight" type="text" maxlength="6" style="width: 40px; FONT-WEIGHT: bold; FONT-SIZE: 13px;" name="weight_1" id="weight_1" tabindex="2" value=""></td>
For Row 2
<tr><td>2</td>
<td><input class="height" type="text" maxlength="6" style="width: 40px; FONT-WEIGHT: bold; FONT-SIZE: 13px;" name="height_2" id="height_2" tabindex="3" value=""></td>
<td><input class="weight" type="text" maxlength="6" style="width: 40px; FONT-WEIGHT: bold; FONT-SIZE: 13px;" name="weight_2" id="weight_2" tabindex="4" value=""></td>
我想要做的是取1行的總高度 - 30跨度ID,並顯示「total_height_for_col_1 「與同爲重
然後行31-60將成爲COL_2和61-90將成爲col_3
我JsFiddle,爲的jsfiddle例如,我得到了4盒。
用JavaScript,我想能夠計算框1和框2的總和,然後框3和框4。
這個例子只用了4箱,在現實中我得到了90個箱,並通過30分割每跨度ID
所有的行都在同一個標籤內嗎? – artm 2014-10-07 08:20:00
你能提供一個DOM lookalike的例子嗎? – Dionys 2014-10-07 08:31:00
@artm和Guilaume,我添加了我的代碼示例 – 2014-10-07 09:12:44