I use jQuery to traverse table data, why can I only take out the first row of data? As shown in the figure, if there are three rows of data in the table, only the first row of data will be repeated three times. Code: Please help me, masters, thank you!
$("#btn_show").click(function () { var tr = $('#tbl2 tbody').children('tr'), list =[], code, name, quan, dwei, spec, pric, amot, cont; tr.each(function(){ var tdArr = $(this).children(), //id = $(this).attr('data-id'), code = $("input[name='code']:eq(1)").val(); name = $("input[name='name']:eq(1)").val(); quan = $("input[name='quan']:eq(1)").val(); dwei = $("input[name='dwei']:eq(1)").val(); spec = $("input[name='spec']:eq(1)").val(); pric = $("input[name='pric']:eq(1)").val(); amot = $("input[name='amot']:eq(1)").val(); cont = $("input[name='cont']:eq(1)").val(); trList = {}; jQuery.extend(trList, { //id: id, code : code, name : name, quan : quan, dwei : dwei, spec : spec, pric : pric, amot : amot, cont : cont }); list.push(trList); }); console.log(list); }); });