首页 > 其他 > 详细

localStorage 储存与读取

时间:2018-09-17 18:59:29      阅读:152      评论:0      收藏:0      [点我收藏+]
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 储存与读取

原文:https://www.cnblogs.com/Millet-23/p/9663441.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!