我用jQuery遍历表格数据,为什么只能取出第一行的数据?如图,如果表格中是三行数据,也只会把第一行数据重复3次。代码:还请大神们帮帮我,谢谢了!
$("#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); }); });