[英]how to live update data on localStorage.length()
how to update data localStorage.length
without reload page ? 如何更新数据
localStorage.length
而不重新加载页面?
on event click, localStorage.SetItem(Item.name, count)
Then data update it with the function .text(localStorage.length)
, but data not updated. on event click,
localStorage.SetItem(Item.name, count)
然后数据用函数.text(localStorage.length)
更新它,但数据没有更新。 thanks 谢谢
When you refresh the page you load the last localStorage.length
. 刷新页面时,加载最后一个
localStorage.length
。 But when you reset the cart you do localStorage.clear();
但是当你重置购物车时,你会做
localStorage.clear();
so you empty the localStorage
. 所以你清空
localStorage
。 In the next line you change the cart text: $('#cart_total').text('(' + storageCount + ')');
在下一行中,您可以更改购物车文本:
$('#cart_total').text('(' + storageCount + ')');
and you load the variable storageCount
, but the problem is that you never updated that variable. 并且您加载变量
storageCount
,但问题是您从未更新该变量。
Use this: 用这个:
$('#reset').on('click', function() {
localStorage.clear();
$('#cart_total').text('(' + localStorage.length + ')');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.