拼接数组

var dataObj = $('input[name="checkAll"]:checked').map(function(el) {
    return {
        
        productId: $(this).parents('li').attr('name'), // id
        productName: $(this).parents('li').find('span').html(), //商品名称
        productImage: $(this).parents('li').find('img').attr('src'), //商品图片地址1
        productPrice: $(this).parents('li').find('span').attr('name'), //商品价格
        productUrl: $(this).parents('li').find('span').attr('id') //第三方商品地址1

    }
}).get()

consoloe.log(dataObj)//数组

原始:

$('input[name="checkAll"]:checked').each(function() { //遍历每一个input的复选框,其中选中的执行函数 

    listLi.name = $(this).parents('li').find('span').html();                       
    listLi.prce = $(this).parents('li').find('p').html();                       
    listLi.img = $(this).parents('li').find('img').attr('src');
    listLi.id = $(this).parents('li').attr('id');
    
    //console.log(listLi.id)
})
原文地址:https://www.cnblogs.com/rockyan/p/9484953.html