zoukankan      html  css  js  c++  java
  • HTML5的存储

    1.客户端存储的两种方式

    localStoryage:没有时间限制的。

    sessionStoryage:针对一个session的数据存储。(浏览器关闭掉之后就会销毁)

    2.localStoryage

    原理:当使用localStoryage存储的时候,会存储在浏览器(这里以谷歌浏览器为例)的Resource下(新版的谷歌浏览器是在Application下)的localStoryage中。

    实例:

    <body >    
            <textarea id="textarea" style=" 200px;height: 200px;border: 1px solid black;"></textarea>
            <button id="button">保存</button>
    <script>
        var textarea = document.getElementById('textarea');
    //之后打开会进行读取
    if(localStorage.text){ textarea.value = localStorage.text; } var button = document.getElementById('button'); button.onclick = function(){
    //点击后进行保存 localStorage.text
    = textarea.value; } </script> </body>

    3.seesionStoryage

    原理:当使用seesionStoryage存储的时候,会存储在浏览器(这里以谷歌浏览器为例)的Resource下(新版的谷歌浏览器是在Application下)的sessionStoryage中。

    实例:

    <body >    
            <textarea id="textarea" style=" 200px;height: 200px;border: 1px solid black;"></textarea>
            <button id="button">保存</button>
    <script src="js/easeljs.min.js"></script>
    <script>
        var textarea = document.getElementById('textarea');
        if(sessionStorage.text){
            textarea.value = sessionStorage.text;
        }
        
        var button = document.getElementById('button');
        button.onclick = function(){
            sessionStorage.text = textarea.value;
        }
    </script>
        </body>
  • 相关阅读:
    ES6
    JavaScript中的Function
    正则表达式
    小程序---电影商城---娱乐---电影列表
    小程序---电影商城---第三方组件 vant(vant weapp)
    Nginx 日志格式
    隐藏响应中的server和X-Powered-By
    个人常用的正则表达式(偶尔更新)
    笔记-VUE滚动加载更多数据
    thinkphp5.1+ 使用 Redis 缓存
  • 原文地址:https://www.cnblogs.com/comefuture/p/7600769.html
Copyright © 2011-2022 走看看