zoukankan      html  css  js  c++  java
  • html5缓存

    HTML5 提供了两种在client存储数据的新方法:
    localStorage - 没有时间限制的数据存储
    sessionStorage - 针对一个 session 的数据存储

    这些都是由 cookie 完毕的。


    可是 cookie 不适合大量数据的存储,

    以下一起来看一个localStorage 存储json对象存储格式问题的解决的方法

    <!DOCTYPE HTML>
    <html>
    <body>
    <script type="text/javascript">
    
    var  obj= [{ "name": "a张三", "addr":"天津"},
    			{ "name": "a张狗","addr":"上海"},
    			{ "name": "a王武","addr":"北京"},				      	   
    			];
    
    obj=JSON.stringify(obj);
    //转化为json字符串
    localStorage.setItem("temp2",obj);
    //返回字符串
    //typeof localStorage.getItem("temp2");
    
    //返回字符串转化为json对象
    obj=JSON.parse(localStorage.getItem("temp2"));
    
    document.write(obj[0].name);
    
    </script>
    </body>
    </html>
    
    localStorage.a = 3;//设置a为"3"
    localStorage["a"] = "sfsf";//设置a为"sfsf",覆盖上面的值
    localStorage.setItem("b","isaac");//设置b为"isaac"
    var a1 = localStorage["a"];//获取a的值
    var a2 = localStorage.a;//获取a的值
    var b = localStorage.getItem("b");//获取b的值
    localStorage.removeItem("c");//清除c的值 


    这里最推荐使用的自然是getItem()和setItem()。清除键值对使用removeItem()。
    假设希望一次性清除全部的键值对,能够使用clear()。


  • 相关阅读:
    随笔——关于读论文
    enumerate
    torch.max
    C# WPF侧边栏导航菜单(Dropdown Menu)
    C# WPF过渡效果实现(C# WPF Material Design UI: Transitions)
    用C# WPF简单实现仪表控件
    自定义滚动条(Custom ScrollBar)
    从头实现一个WPF条形图
    漂亮的无序列表样式
    C# WPF实用的注册窗体
  • 原文地址:https://www.cnblogs.com/brucemengbm/p/6942135.html
Copyright © 2011-2022 走看看