jQuery Clone table row

前端 未结 7 1157
悲&欢浪女
悲&欢浪女 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:24

    Here you go:

    $( table ).delegate( '.tr_clone_add', 'click', function () {
        var thisRow = $( this ).closest( 'tr' )[0];
        $( thisRow ).clone().insertAfter( thisRow ).find( 'input:text' ).val( '' );
    });
    

    Live demo: http://jsfiddle.net/RhjxK/4/


    Update: The new way of delegating events in jQuery is

    $(table).on('click', '.tr_clone_add', function () { … });
    

提交回复
热议问题