jQuery Clone table row

前端 未结 7 1158
悲&欢浪女
悲&欢浪女 2020-11-30 03:56

I have a table with an Add button on the end. When you click this button I want a new table row to be created underneath the current one. I also want the input fields on thi

7条回答
  •  感情败类
    2020-11-30 04:09

    Is very simple to clone the last row with jquery pressing a button:

    Your Table HTML:

    ID Header 1
    1 Line 1

    JS:

    $(document).on('click', '#addRowButton', function() {
        var table = $('#tableExample'),
            lastRow = table.find('tbody tr:last'),
            rowClone = lastRow.clone();
    
        table.find('tbody').append(rowClone);
    });
    

    Regards!

提交回复
热议问题