search

Home  >  Q&A  >  body text

javascript - jQuery gets all data from table

As shown in the picture, clicking the Add a Row button will add a row. After filling in the data, click Save below and it will be inserted into the database. The question now is how to get all the data in the table? Please post the code

phpcn_u1582phpcn_u15822693 days ago897

reply all(1)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-06-30 10:00:28

    var set = [];
    $('table tr').each(function() {
        var row = [];
        
        $(this).find('td').each(function() {
            row.push($(this).text());
        });
        
        set.push(row);
    });

    In this way, all the td items in the entire table will be stored in a two-dimensional array set in order from row to column, similar to the structure below

    [
        [列1, 列2, ...], // 行1
        [列1, 列2, ...], // 行2
        ...
    ]

    reply
    0
  • Cancelreply