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"]) } } }
原文地址:https://www.cnblogs.com/Millet-23/p/9663441.html
时间: 2024-11-07 05:33:58