Add table row in jQuery

前端 未结 30 2331
既然无缘
既然无缘 2020-11-21 05:40

What is the best method in jQuery to add an additional row to a table as the last row?

Is this acceptable?

$(\'#myTable\').append(\'

        
30条回答
  •  攒了一身酷
    2020-11-21 06:04

    I recommend

    $('#myTable > tbody:first').append('......'); 
    

    as opposed to

    $('#myTable > tbody:last').append('......'); 
    

    The first and last keywords work on the first or last tag to be started, not closed. Therefore, this plays nicer with nested tables, if you don't want the nested table to be changed, but instead add to the overall table. At least, this is what I found.

提交回复
热议问题