码迷,mamicode.com
首页 > Web开发 > 详细

html5---本地存储账号

时间:2015-05-13 10:35:08      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:cookie   html5   

<!doctype html>
<html>
    <head>
    </head>
    <body>
    <script>
    //cookie存储量小,生存周期与sessionStoage一样,localStorage存储量大,永久保存
     document.cookie="name=zhangsan";
     alert(document.cookie);
     localStorage.setItem("name","lisi");
     alert(localStorage.getItem("name"));
     sessionStorage.setItem("name","wangwu");
     alert(sessionStorage.getItem("name"))
    </script>
    </body>
</html>



<!doctype html>
<html>
    <head>
    <script>
     window.onload=function  () {
      var names=document.getElementsByName("names")[0]; //获取姓名
      var pass=document.getElementsByName("pass")[0];  //获取密码
      var save=document.getElementsByName("save")[0];  //获取是否保存
      if(localStorage.getItem("names")&&localStorage.getItem("pass")){//如果本地已经存储过
         names.value=localStorage.getItem("names");     //更新
         pass.value=localStorage.getItem("pass");
         save.checked=true;
      }
      save.onclick=function  () {
       if(save.checked){    //如果要保存
         localStorage.setItem("names",names.value);
         localStorage.setItem("pass",pass.value);
       }else{
         localStorage.removeItem("names");
         localStorage.removeItem("pass");
       }
      }
     }
    </script>
    </head>
    <body>
       用户名:<input type ="text" name="names"><br/>
       密码:<input type="password" name="pass"><br/>
       是否永久保存<input type="checkbox" name="save">
    </body>
</html>

html5---本地存储账号

标签:cookie   html5   

原文地址:http://blog.csdn.net/sjtu_chenchen/article/details/45677303

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!