• js 本地缓存localStorage


    1.localStorage - 没有时间限制的数据存储 
    
       var arr=[1,2,3];
       localStorage.setItem("stor",arr); 
       console.log(localStorage.getItem("stor"));
    
     2.清空localStorage
      localStorage.clear(); //
    
     3.删除键值对
      localStorage.removeItem("stor");  
      注意:存入的数据只能以字符串形式存入。
    
    
    //JSON对象转JSON字符串
      var obj = {"a": 1,"b": 2};
      obj = JSON.stringify(obj); //转化为JSON字符串
      localStorage.setItem("stor1", obj);
    
      //JSON字符串转JSON对象
      obj=JSON.parse(localStorage.getItem("stor1"));

     例如 6个元素 每次刷新页面依次出现一个(不重复出现),最后一个元素出现后从新开始:

    <script>
    // JavaScript Document
    tips = new Array(6);
    tips[0] = 'K6661112228';
    tips[1] = 'sy66688815';
    tips[2] = 'y6668887788';
    tips[3] = 'xzc17051001008';
    tips[4] = 'Yn6661118882255';
    tips[5] = '258258005858';
    
    var i=localStorage.getItem("index");
    if(i==null)
    {
        index=0;
        localStorage.setItem("index", "0")
    }else
    {
        
        var i=localStorage.getItem("index");
            index=parseInt(i)+1;
            if(index>5)
            {
                    index=0;
        localStorage.setItem("index", "0")
            }else{
                localStorage.setItem("index", index)
            }
    }
    </script>
  • 相关阅读:
    P3241 [HNOI2015]开店 动态点分治
    P4199 万径人踪灭 FFT + manacher
    P4173 残缺的字符串
    P3338 [ZJOI2014]力
    CF1005F Berland and the Shortest Paths
    CF567E President and Roads
    P2446 [SDOI2010]大陆争霸
    CF1082G Petya and Graph
    CF1082E Increasing Frequency
    直接查数据导出xls
  • 原文地址:https://www.cnblogs.com/bin521/p/10565644.html
Copyright © 2020-2023  润新知