寫了一個簡單的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);
    });
});

arrow
arrow
    創作者介紹
    創作者 衛斯理不理 的頭像
    衛斯理不理

    衛斯理不理學習心得與技術日常

    衛斯理不理 發表在 痞客邦 留言(0) 人氣()