需求:
把每次搜索的关键词组成json格式放入localstorage,然后加载这个json做成搜索历史,目前的问题是没一次放入localstorage都是新增覆盖了之前的(如下图),需要的是追加,求解!
// 新增搜索词存放localStorage
var historyArr=[];
function addSearchList(){
var historyObj = {};
var sInputVal = sInput.val();
if(sInputVal.length != 0){
historyObj.search_name = sInputVal;
historyObj.search_address = 'search-filter.html?search=' + escape(sInputVal);
console.log(historyArr.length);
historyArr.push(historyObj);
localStorage.setItem("searchhistory",JSON.stringify(historyArr));
}
}
森栏
MMMHUHU
相关分类