Removing items from the localStorage

后端 未结 4 1213
长发绾君心
长发绾君心 2021-01-13 14:54

I\'m trying to remove the individual items from the localStorage. I\'m using localStorage for storing selected list items in the listview. I attached the checkboxes for remo

4条回答
  •  情话喂你
    2021-01-13 15:47

    I think the problem is in this part:

    $("#delete").on('click', function() {
                var checked = $('#add #check:checkbox:checked');
                var url = localStorage.key(checked);
                localStorage.removeItem(url);
                $("#favoritesList").listview('refresh');
    });
    

    you are not using correct key for deleting and its because you are using :

    var url = localStorage.key(checked);
    

    and checked==[Object]==1 so you are pointing to localStorage.key(1)


    for solving this problem you can both use key=localStorage.key(some);localStorage.removeItem(key); and localStorage.removeItem(some); but the important part is that you should match 'an index(first way)' or a 'key value(the second way)' for each checkbox and I can help you if I have the complete code (I think still there are some part of HTML or codes that are related)(also it would be so good if you put a fiddle of your codes)

提交回复
热议问题