因此,您必须做到以下几点:
1) 而不是使用
id
属性,最好使用
class
属性以便于jQuery。。
<select name="size[]" id="box1" class="box1">
<option value="20">20</option>
<option value="35">35</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
x
<input name="qty[]" id="box2" class="box2" type="text" value="" />
= <input name="multiply[]" id="answer" class="answer" type="text" value="" />
注意:不要忘记更改
Add More
作用
2) 以下是您如何计算总数,这是通过更改
<input>
或
<select>
function calTotal(){
var total = 0;
$(".my-form .text-box .answer").each(function(){
total += Number($(this).val());
});
$(".GrandTotal").text("");
$(".GrandTotal").text(total);
}
$(".my-form").on('input', '.box2', function(){
var total_row = $(this).val();
total_row *= $(this).siblings(".box1").val();
$(this).siblings(".answer").val(total_row);
calTotal();
});
$(".my-form").on('change', '.box1', function(){
var total_row = $(this).val();
total_row *= $(this).siblings(".box2").val();
$(this).siblings(".answer").val(total_row);
calTotal();
});
看看这个
Fiddle
..