您好,欢迎访问一九零五行业门户网

关于本地的Web-storage存储的详细介绍

本文给大家介绍一下webstorage存储分类,客户端和服务端,以及带大家认识web储存,随着web应用的发展,客户端的储存越来越多,今天给大家详细的介绍一下web-storage存储的处方式。
web storage,
localstorage
sessionstorage:
1 检测浏览器是否支持数据存储
注意:在html5中  使用javascript 来存储和访问数据的。
2. localstorage 设置 /获取数据
存储在客户端的(移动端  手机 平板…) 没有时间限制的
常用方法:
赋值:
window.localstorage .setitem(“变量名称”,”val”) ---》localstorage.变量名称 = 值
取值:
window.localstorage.getitem(“变量名称”)-à localstorage.变量名称
注意:测试localstorage 需要到 php环境下测试
3.sessionstorage 设置/获取数据
存储在服务器端(sohu 美食天下)
赋值:
window. sessionstorage .setitem(“变量名称”,”val”) ---》sessionstorage .变量名称 = 值
取值:
window. sessionstorage .getitem(“变量名称”)-à sessionstorage .变量名称 sessionstorage:
关闭浏览器
调用:sessionstorage.removeitem(“bname”); 清空数据
案列代码:
<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> <link rel="stylesheet" href="css/style.css"> </head> <script type="text/javascript"> //window.localstorage /sessionstorage //if(true) true 不空 0 0.0 “0” window.localstorage 有值 if(window.localstorage){ alert(111); } if(window.sessionstorage){ alert(222); } </script> <body> </body> </html>
相信看了这些案例你已经掌握了方法,更多精彩请关注其它相关文章!
相关阅读:
css的文本字体颜色如何设置
css3中hover动画的颜色动画怎么使用
css里的盒子模型的种类区别
以上就是关于本地的web-storage存储的详细介绍的详细内容。
其它类似信息

推荐信息