阅读背景:

在本地存储中添加新对象会覆盖旧对象

来源:互联网 

   
var  product,    
   numberof,   
   quantity,  
   price,  
   localStorageProd;

function storeProdStorage( product , numberof, quantity, price ) {
    var itemsArray = [];
    newItem = {
      product : product ,
      numberof : numberof ,
      quantity : quantity ,
      price : price 
    };
  
    if (localStorage["prodbank"] != null) {
      var localStorageContentObject = JSON.parse(localStorage["prodbank"]);
      itemsArray.push(localStorageContentObject);

      for( var i = 0; i < itemsArray.length ; i++ ) {
        if(itemsArray[i].product == product) {
            itemsArray[i].quantity = quantity; 
            itemsArray[i].price = price;
            localStorage.setItem('prodbank', JSON.stringify(itemsArray[i]));  
        } else {
          itemsArray.push(newItem);
        localStorage.setItem('prodbank', JSON.stringify(itemsArray));  
        }
      }    
            
    } else {
      localStorage.setItem('prodbank', JSON.stringify(newItem));  
    }
}  
  
$(function() {
    $(".quantity-slider").slider({
        range: "min",     
        value: 50,
        min: 50,
        max: 1000,
        step: 50,
        
        slide: function(e,ui) { 
          var quant = $('.quantity').html(commaSeparateNumber((ui.value) *10)); 
          var price = $('.price').html(ui.value);
             if($('.price').html() == "50" ) {
                $('.quantity').html(250);
             }
      
       product = $(".pricing-title").html();
       numberof = $(".pricing-code .form-section h3").contents().get(0).nodeValue;  
       quantity = $(".pricing-code .form-section h3 .quantity").eq(0).html();  
       price = $(".pricing-code .form-section h3 .price").eq(0).html();
          
       storeProdStorage(product , numberof, quantity, price );
     } 
    });

    $('.quantity').html(($( ".quantity-slider" ).slider("value"))*5);
});
  
     
var  product,    
   numberof, 



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: