【发布时间】:2018-08-12 01:47:25
【问题描述】:
我制作了一个“结帐”按钮,当按下它时,它会将 html 表中的所有数据收集到一个对象数组中。问题是我如何将 var arrData 数据传递到下一页。 jquery 新手,在此先感谢。
$("#checkout").on('click',function(){
var arrData=[];
$("#table tr").each(function(){
var currentRow=$(this);
var col1_value=currentRow.find("td:eq(0)").text();
var col2_value=currentRow.find("td:eq(1)").text();
var col3_value=currentRow.find("td:eq(2)").text();
var col4_value=currentRow.find("td:eq(3)").text();
var obj={};
obj.col1=col1_value;
obj.col2=col2_value;
obj.col3=col3_value;
obj.col4=col4_value;
arrData.push(obj);
});
console.log(arrData);
});
【问题讨论】:
-
无法使用 jQuery,您需要在 URL 中将 obj 作为查询参数传递,然后在其他页面中读取/解析 url
-
@Helpinghand 你能举个例子吗,还是很模糊。
-
当您切换到另一个页面时,所有变量都会刷新。因此通过 url 是一个不错的选择。本地存储也是另一种方式
-
我理解了这个理论,但我如何将它应用为代码,你能为像我这样的初学者做出 1 个好的答案吗? @Helpinghand
标签: javascript jquery html css