我用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); }); });#