我正在尝试在本地存储购物车

时间:2019-09-19 12:41:39

标签: javascript

numPlass++;
let names = [];
var set = cart_item.childNodes[numPlass].innerHTML;
names.push(set);
let local = JSON.stringify(names);

localStorage.setItem('name' ,local)

它只会显示最后一个,并且不会在数组中放置多个

1 个答案:

答案 0 :(得分:0)

let names = JSON.parse(localStorage.getItem('name'))|| [];
var set = cart_item.childNodes[numPlass].innerHTML;
names.push(set);
localStorage.setItem('name', JSON.stringify(names));