嗨,我想每次用户单击时都在现有数组中添加一个新值, 但是用我的代码,每次都删除数组。你能帮我吗? 这是我的代码:
cameraSelected(){
var getId = document.querySelector('.linkCart');
var typeCamera = document.querySelector('.name');
var priceCamera = document.querySelector('.price');
var storeName = [];
var storePrice = [];
var cameras = {
name : typeCamera.textContent,
price : priceCamera.textContent
}
var nameItems = localStorage;
var priceItems = localStorage;
getId.addEventListener("click", (e)=>{
e.preventDefault();
storeName.push(cameras.name);
storePrice.push(cameras.price);
for (let names in storeName){
nameItems.setItem("cameras", JSON.stringify(storeName));
}
for (let prices of storePrice){
priceItems.setItem("prices", storePrice);
}
});
}