localStorage 储存与读取
Posted millet-23
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了localStorage 储存与读取相关的知识,希望对你有一定的参考价值。
window.onload=function(){ /** *其实也没那么难, *localStorage.setItem(json) 向本地储存值 *window.localStorage["键"] 得到本储存的值 */ var setl = document.getElementById("setl"); setl.onclick=function(){ var name = document.getElementById(‘name‘).value; localStorage.setItem("name",name); var password = document.getElementById("password").value; localStorage.setItem("password",password); } var redl = document.getElementById("redl"); redl.onclick=function(){ var storage = window.localStorage; var name = storage["name"]; var password = storage["password"]; if(storage["password"]== undefined && storage["name"]==undefined){ console.log("没有信息") } else{ console.log(storage["password"],storage["name"]) } } }
以上是关于localStorage 储存与读取的主要内容,如果未能解决你的问题,请参考以下文章