所以我基本上具有在格式多行:遍歷表格行計算總計(數量*每行成本)
<tr class="items" id="items">
<td><input type="text" name="description[]" id="description[]" style="width:450px;" /></td>
<td><input type="text" name="quantity[]" id="quantity[]" style="width:40px;text-align:center;" onblur="CaclulateQuantityTotal();"/></td>
<td><input type="text" name="cost[]" id="cost[]" style="width:40px;text-align:center;" onblur="CaclulateCostTotal();"/></td>
<td><select name="currency[]" id="currency[]"><option value="USD">USD</option><option value="CAD">CAD</option></select></td>
<td style="text-align:right;"><input type="text" name="total[]" id="total[]" style="width:40px;text-align:center;" readonly="readonly" /></td>
<td><a href="#" id="add_item">+</a></td>
</tr>
我基本上想總[]是(該行)成本*數量。
我的問題是我知道如何循環遍歷所有數量[]和貨幣[]使用jquery,但我不知道如何匹配它們在每行的基礎上。
任何人都可以幫忙嗎?
首先,從您的所有元素中刪除的ID - 你不應該有一個頁面上有兩個元素具有相同的ID 。 – Blazemonger
在「tr」上使用.each獲得行 – Flo
'$('tr.items')。each(function(index,cItem){var jItem = $(cItem); jItem.find('input [name^('input^[name] = value]')。val(parseFloat(jItem.find('input [name^= cost]').val())* parseFloat(jItem.find ));});' – Orbling