How to iterate through a table rows and get the cell values using jQuery

前端 未结 5 1416
天涯浪人
天涯浪人 2020-12-30 04:16

I am creating the below table dynamically using jQuery... After executing my code I get the table as below:

5条回答
  •  情深已故
    2020-12-30 04:42

    I got it and explained in below:

    //This table with two rows containing each row, one select in first td, and one input tags in second td and second input in third td;

//call on click of Save button; $('#saveDtls').click(function(event) { var TableData = []; //initialize array; var data=""; //empty var; //Here traverse and read input/select values present in each td of each tr, ; $("table#tableID > tbody > tr").each(function(row, tr) { TableData[row]={ "fromGroup": $('td:eq(0) select',this).val(), "toGroup": $('td:eq(1) input',this).val(), "level": $('td:eq(2) input',this).val() }; //Convert tableData array to JsonData data=JSON.stringify(TableData) //alert('data'+data); }); });

提交回复
热议问题