项目描述
上传时间
浏览人数
js部分
<script type="text/javascript"> let y="hutao" let title=[ "火影忍者","海贼王","死神","刀剑神域","浪客行","浪客剑心" ] let get={ gta:"Tom", ff:"kid", fc:"travel", sc:"priest", "3rd":"stigmata", } console.log(get); let a=JSON.stringify(title) let b=JSON.stringify(get) //localStorage.setItem("title",a) /*投值*/ //localStorage.setItem("get",b) //let c=localStorage.getItem("title")/*取值*/ //console.log(c); //localStorage.setItem("h",y) //let n=localStorage.getItem("h") //console.log(n); //console.log(JSON.parse(c)); /*变成 数组/对象*/ //console.log(title.length); /*title长度 //console.log(localStorage.length); /*缓存长度*/ //localStorage.removeItem("title") /*移除*/ //let d=localStorage.key(0) /*找key(0)*/ //console.log(d); //localStorage.removeItem(localStorage.key(0)) /*移除缓存中(缓存的key(0))*/ //localStorage.clear() /*清空*/ sessionStorage.setItem("title",a) sessionStorage.setItem("get",b) let c=sessionStorage.getItem("title") console.log(c); sessionStorage.setItem("h",y) let n=sessionStorage.getItem("h") console.log(n); console.log(JSON.parse(c)); console.log(title.length); console.log(sessionStorage.length); sessionStorage.removeItem("title") let d=sessionStorage.key(0) console.log(d); sessionStorage.removeItem(sessionStorage.key(0)) sessionStorage.clear() </script>
ps:localStorage和sessionStorage的区别在于前者为永久缓存,除非你清除缓存,后者为临时缓存,如关闭当前页面,它将无法存在