Javascript jquery购物车从本地存储中删除表行
当我点击“x”按钮时,我正试图从购物车(和本地存储)中删除一行 以下是我目前掌握的情况:Javascript jquery购物车从本地存储中删除表行,javascript,jquery,local-storage,shopping-cart,Javascript,Jquery,Local Storage,Shopping Cart,当我点击“x”按钮时,我正试图从购物车(和本地存储)中删除一行 以下是我目前掌握的情况: for (i=0; i<numCart; i++){ var button = $('<td>'+infoCartItems[i].button+'</td>').addClass("checkoutTitles"); button.text('x'); row.append(button); $(".cartTable").append(ro
for (i=0; i<numCart; i++){
var button = $('<td>'+infoCartItems[i].button+'</td>').addClass("checkoutTitles");
button.text('x');
row.append(button);
$(".cartTable").append(row);
}
以下是我用来从购物车中删除商品的代码:
$(".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();
})) 以下是我用来从购物车中删除商品的代码:
$(".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();
})) 当前行为和预期行为是什么?当前,当我点击“x”时,什么都没有发生当前行为和预期行为是什么?当前,当我点击“x”时,什么都没有发生