sessionStorage 浏览器缓存
$("#int").on("search",function() { var $value = $(".sch input").val(); arr.push($value); sessionStorage.setItem("data", arr) window.location.href = "/wap/searchgoods-index.html?search_keywords="+$value; }) $(window).on("load",function(){ var data = sessionStorage.getItem("data"); if(data != null){ data = data.split(","); data = remov(data); for(var i = 0; i < data.length; i++) { $(".hstl .hst").append("<li>"+data[i]+"</li>"); } } /*历史记录单个操作*/ $(" .hstl .hst li").on("click",function() { var $value = $(this).html(); window.location.href = "/wap/searchgoods-index.html?search_keywords="+$value; }) })
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>H5的storage</title> </head> <body> <input type='button' onclick='setItems()' value='存值' /> <input type='button' onclick='getItems()' value='取值' /> <input type='button' onclick='deleteItem()' value='删除' /> </body> <script src="js/jquery.min.js"></script> <script> //localStorage存值永久有效 function setItems(){ var user = {}; user.name = 'Adam Li'; user.age = 25; user.home = 'China'; localStorage.setItem('userinfo',JSON.stringify(user)); } //localStorage取值 function getItems(){ var data = JSON.parse(localStorage.getItem('userinfo')); console.log("name:"+data.name+'\r age:'+data.age+"\r home:"+data.home); } //localStorage删除指定键对应的值 function deleteItem(){ localStorage.removeItem('userinfo'); console.log(localStorage.getItem('userinfo')); } </script> </html>
相关推荐
coolhty 2020-05-09
zxznsjdsj 2019-12-18
HSdiana 2019-11-09
爱好HtmlCssJs 2019-11-07
javazhuanzai 2019-11-05
owhile 2015-02-19
WCschool官方 2015-10-23
htmlman0 2017-12-09
hanniuniu 2019-06-30
Noontec 2019-06-29
纯屌丝程序猿 2017-12-09
纯屌丝程序猿 2016-12-22
我的一个小黑人 2016-11-01
墨龙吟 2019-06-28
happyzhangyin 2016-03-19
zljiaa 2015-12-12
wxcmdn 2019-06-27
wxcmdn 2019-06-27