Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jquery购物车从本地存储中删除表行_Javascript_Jquery_Local Storage_Shopping Cart - Fatal编程技术网

Javascript jquery购物车从本地存储中删除表行

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

当我点击“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);

}

以下是我用来从购物车中删除商品的代码:

$(".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”时,什么都没有发生