寫了一個簡單的jQuery 動態新增欄位並計算欄位裡面的值,
但完整一點的程式需要再補充欄位值的判斷是否為整數匯一其他不同的需求進行輸入值過濾與判斷。
DEMO CODE :https://jsbin.com/zuligomigi/edit?html,js,output
關鍵程式碼記錄在下面:
$(document).ready(function() {
$('body').on('click','#add_row',function(){
$('#template').find('.row_data').clone().appendTo($('#append_position'));
});
$('#example').on('change', '.a_row', function(event) {
event.preventDefault();
var row_total = 0;
$('.a_row').each(function(index, el) {
row_total = row_total + Number($(this).val());
});
$('#total').html('a_row_total = '+ row_total);
console.log(row_total);
});
});
文章標籤
全站熱搜