Add table row in jQuery

前端 未结 30 3056
既然无缘
既然无缘 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:13

    $('#myTable').append('my datamore data');
    

    will add a new row to the first TBODY of the table, without depending of any THEAD or TFOOT present. (I didn't find information from which version of jQuery .append() this behavior is present.)

    You may try it in these examples:

    h1h2
    12
    f1f2

    h1h2
    12
    34
    f1f2

    h1h2

    12

    In which example a b row is inserted after 1 2, not after 3 4 in second example. If the table were empty, jQuery creates TBODY for a new row.

提交回复
热议问题