Javascript 从本地存储更新变量
刷新页面时,TotalPrice的值为true,直到单击按钮,TotalPrice的值从0开始。那么现在如何将新价格添加到Javascript 从本地存储更新变量,javascript,jquery,Javascript,Jquery,刷新页面时,TotalPrice的值为true,直到单击按钮,TotalPrice的值从0开始。那么现在如何将新价格添加到TotalPrice /********************************************************************/ var price=0; var TotalPrice=localStorage.getItem("x"); $("#total").html(TotalPrice); $(".addToCard
TotalPrice
/********************************************************************/
var price=0;
var TotalPrice=localStorage.getItem("x");
$("#total").html(TotalPrice);
$(".addToCard").on("click",function(){
if($(this).text()=='add to cart')
{$(this).html("remove from cart");
var clickedButtonIndex=( $('button').index(this) );
clickedButtonIndex=clickedButtonIndex-2;
price +=resp2[clickedButtonIndex].price;
/************adding to local storage**************/
$("#total").html(price);
localStorage.setItem("x",price);
有什么问题吗?这个问题很不清楚,而且你留下了很多代码,这使得你很难理解这个问题是什么。请留下您遇到的问题并解决您的问题,我们将尽力提供帮助