可以在提交的时候再获取产品名称和数量发送到服务器端 在线演示 $('#btn').click(function(){ var items = new Array(); $('.content').each(function(){ $this = $(this); var name = $this.find('p').text(); var qty = $this.find('input:button:eq(1)').val(); items.push({"name": name, "qty": + qty}); }); var s = JSON.stringify(items); console.log(s); });
在线演示 $('#btn').click(function(){
var items = new Array();
$('.content').each(function(){
$this = $(this);
var name = $this.find('p').text();
var qty = $this.find('input:button:eq(1)').val();
items.push({"name": name, "qty": + qty});
});
var s = JSON.stringify(items);
console.log(s);
});