[英]jquery shopping cart delete table row from local storage
當我點擊“ x”按鈕時,我試圖從購物車(和本地存儲)中刪除一行。
這是我到目前為止的內容:
for (i=0; i<numCart; i++){
var button = $('<td>'+infoCartItems[i].button+'</td>').addClass("checkoutTitles");
button.text('x');
row.append(button);
$(".cartTable").append(row);
}
這是我的存儲代碼:
var newItem= new Bun(pack, current, flavor2nd, flavor3rd, money);
var existingCartItems = JSON.parse(localStorage.getItem("itemsArray"))||[];
existingCartItems.push(newItem);
localStorage.setItem("itemsArray", JSON.stringify(existingCartItems));
這是我用來從購物車中刪除商品的代碼:
$(".remove").on('click', function() {
// get the index of the row in the table
var index = $(this).parent().parent().index();
index = index - 1;
// remove item from table
$(this).parent().parent().remove();
// remove item from the cart local storage
var cart = JSON.parse(localStorage.getItem("itemsArray"));
cart.splice(index, 1);
localStorage.setItem("itemsArray", JSON.stringify(cart));
location.reload();
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.