我是想把localStorage里面的数据显示到ul里面,
尝试过多次没有成功
以下是html和JavaScript的代码
希望能帮助我解决不显示的问题
```html
<div id="sh_for_rmd_rods">
<div class="rods_font-del_box">
<span class="rods_font">搜索历史
<span id="Rod_Del" class="rods_del">全部删除
</div>
<ul id="ShowHistory">
</div>
```javascript
SearchBtn.onclick = function(){
let userVal = SearchInput.value;
let localCon = localStorage.getItem('SearchInputValue');
arr = localStorage.getItem('SearchInputValue') ? arr = JSON.parse(localStorage.getItem('SearchInputValue')) : [];
if(userVal == null||userVal == ''||userVal == undefined||userVal.replace(/(^\s*)|(\s*$)/g, "")==''){
return;
}else{
let arr = [];
}
if(arr.indexOf(userVal)== -1){
arr.unshift(userVal);
};
if(arr.length >= 15){
arr.splice(arr.indexOf(14),1);
};
localStorage.setItem('SearchInputValue',JSON.stringify(arr));
showLog();
};
rods_del.onclick = function () {
localStorage.removeItem('SearchInputValue');
};
ShowHistory.addEventListener('click', function(e){
if(e.target.nodeName == 'Li'){
let datas = JSON.parse(localStorage.getItem('SearchInputValue'));
console.log(e.target.dataset['index']);
datas.splice(e.target.dataset['index'],1);
localStorage.setItem('SearchInputValue',JSON.stringify(datas));
showLog();
};
});
function showLog(){
let locals = JSON.parse(localStorage.getItem('SearchInputValue')) || [];
let showHistorysHtml = '';
for(let i = 0; i <locals.length; i++){
showHistorysHtml += '+locals[i]+ ';
}
ShowHistory.innerHTML = showHistorysHtml;
};