jQuery traversing table error
P粉154884468
P粉154884468 2023-03-29 18:20:32
0
0
621

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);
    });	  
});

360截图20230329170742081.jpg

P粉154884468
P粉154884468

reply all(0)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!