Using Jquery, replace one row in table with a new one

前端 未结 4 1181
忘掉有多难
忘掉有多难 2021-02-08 05:09

Say I have a table:

12Edit
相关标签:
4条回答
  • 2021-02-08 05:47

    Use jQuery.replaceWith()

    $(document).ready(function() {
      $('#mytable .edit').click( function() {
        var tr = $(this).parent();
        var new_row = '<tr class="new_row"><td>3</td><td>4</td><td>Save</td></tr>';
        tr.replaceWith(new_row);
      });
    });
    
    0 讨论(0)
  • 2021-02-08 05:47

    jQuery's replaceWith(). Example:

    $(document).ready(function() {
        $('#mytable .edit').click( function() {
    
            var tr = $(this).parent();
            var new_row = '<tr class="new_row"><td>3</td><td>4</td><td>Save</td></tr>'
            tr.replaceWith(new_row); // code to replace this row with the new_row
        });
    } );
    
    0 讨论(0)
  • 2021-02-08 06:00

    http://jsfiddle.net/hAvyv/

    $('.edit').click(function(){
        $(this).parent().removeClass('old_row').addClass('new_row').html('<td>3</td><td>4</td><td>Save</td>');
    });
    
    0 讨论(0)
  • 2021-02-08 06:12
    $(document).ready(function() {
    
        $('#mytable .edit').click( function() {
    
            var new_row = '<tr class="new_row"><td>3</td><td>4</td><td>Save</td></tr>'
            $(this).parent().replaceWith(new_row);
        });
    
    } );
    
    0 讨论(0)
提交回复
热议问题