HTML5本地数据存储

2019-09-10 郑州网站建设  

HTML5本地数据存储代码:

<script type="text/javascript">

                     function MyClick1(){

                            var username=$("#txtUserName").val(); 

                            var pwd=$("#txtPwd").val();

                            //sessionStorage.setItem("k_username",username);

                            //存储在浏览器缓存里,关闭浏览器就失去数据

                            //sessionStorage.setItem("k_pwd",pwd);

                            localStorage.setItem("k_username",username);

                            //存储在本地文件里

                            localStorage.setItem("k_pwd",pwd);

                            alert("储存成功");

                     }

                     function MyClick2(){

                            //alert(sessionStorage.getItem("k_username"));

                            //alert(sessionStorage.getItem("k_pwd"));

                            //localStorage.removeItem("k_username");

                            //清除key

                            //localStorage.clear();

                            //删除所有

                            alert(localStorage.setItem("k_username"));

                            alert(localStorage.setItem("k_pwd"));

                     }

             

              </script>

                <input type="text" id="txtUserName" />

              <input type="password" id="txtPwd" />


河南郑州做网站首选天择文化,我们专注郑州网站建设网站设计网站制作与开发,是中原地区专业的郑州网络公司,多年来我们一直努力,服务客户数百家,欢迎您的咨询。
本文链接:郑州网络公司http://tzchb.ieyo.com/dede/1788.html转载请标明出处,谢谢合作!
标签:
  • HTML5
  • 数据
  • 代码
  • script
  • 存储
  • 本地