大佬教程收集整理的这篇文章主要介绍了HTML5中的storage存储,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
caicongyang:http://blog.csdn.net/caicongyang
<!DOCTYPE html> <html> <head> <title>storageHtml.html</title> <Meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <Meta http-equiv="description" content="this is my page"> <Meta http-equiv="content-type" content="text/html; charset=UTF-8"> <!--<link rel="stylesheet" type="text/css" href="./styles.css">--> </head> <body> This is my storageHtml page. <br> </body> <script type="text/javascript"> if(window.localStoragE){ alert("您的浏览器支持本地存储!"); //支持键值对的形式-设置键值对 localStorage.setItem("name","张三"); //键值对长度 alert(localStorage.length); //获取键值对的值 alert(localStorage.getItem("name")); //通过索引获取键值对的值 alert(localStorage.key(0)); //移除某个键值对 localStorage.removeItem("name"); //清除所有的键值对 localStorage.clear(); alert(localStorage.length); //localStorage同样支持josn格式的数据对象 var user = { name:"李四",age:"15" }; localStorage.setItem("u1",JSON.Stringify(user)); var u = JSON.parse(localStorage.getItem("u1")); alert(u.Name); } if(window.sessionStoragE){ alert("您的浏览器支持会话存储!"); //sessionStorage的方法与localStorage相同 } //本地存储数据监听 window.onload = function(){ window.addEventListener("storage",function(E){ console.log(E); },truE); }; </script> </html>
以上是大佬教程为你收集整理的HTML5中的storage存储全部内容,希望文章能够帮你解决HTML5中的storage存储所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。