1 for (var i=0, j = _self.sessionStorage.length; i < j; i++){ 2 var key = _self.sessionStorage.key(i); 3 if(jQuery.inArray(key,_self.idArray) <0 && parseInt(key) > 0 ) { 4 _self.idArray.push(key); 5 } 6 } 7 8 //循环数组中的商品id,购物车中展示 9 for(var i = 0;i < _self.idArray.length; i++){ 10 if(sessionStorage.getItem(_self.idArray[i]) !== null){ 11 var rs= sessionStorage.getItem(_self.idArray[i]).split("|"); 12 if(rs[2] !=="0" && rs !==null){ 13 var _temp = $('<div class="am-cartListStyle" id="am-cartListStyle'+rs[4]+'" data-stock="'+rs[3]+'" data-name="'+rs[0]+'" data-price="'+rs[1]+'" data-id="'+rs[4]+'" data-cate="'+rs[5]+'" style="padding-right: 0.8rem;"><p class="am-cartList-title" style=" 13rem;">'+rs[0]+'</p><div class="am-float-rt"><p class="am-price" style="vertical-align: middle;4em;display:inline-block;" data-name="'+rs[0]+'" data-price="'+rs[1]+'" data-id="'+rs[4]+'">¥'+rs[1]+'</p><img id="minus'+rs[4]+'" class="" src="/Application/Home/View/WapSchoolMarket/source/css/images/minus.png" alt=""><input class="am-count" id="am-count'+rs[4]+'" disabled="disabled" value="'+rs[2]+'" style="font-size: 1.7rem;"><img id="plus'+rs[4]+'" src="/Application/Home/View/WapSchoolMarket/source/css/images/plus.png" alt=""></div></div>'); 14 $(".am-cartList").append(_temp); 15 16 }else{ 17 sessionStorage.removeItem(rs[4]); 18 } 19 } 20 }
关于本地存储构成数组以及jquery的inArray方法的使用
本地数据格式:娃娃|1.00|9|416|303|198