zoukankan      html  css  js  c++  java
  • H5本地存储

    在HTML5中可以把数据长期存储在客户端,使用的对象就是localStorage。

    localStorage常用方法有setItem、getItem、removeItem、clear。

    下面是一个存储数组对象的例子,由于localStorage中存储的数据会自动转换为字符串,数组类型则会自动join(","),所以数组元素中最好不要有','。

            function getHistory() {
                var _history = localStorage.getItem("routeHistory");
                if (_history) {
                    return _history.split(",");
                }
                return [];
            }
            function addHistory(newhis) {
                var _history = getHistory();
                if (_history.length >= 10) {
                    _history.pop();
                }
                _history.reverse();
                _history.push(newhis);
                _history.reverse();
                localStorage.setItem("routeHistory", _history);
            }
            function clearHistory() {
                localStorage.removeItem("routeHistory");
            }
    

      

  • 相关阅读:
    C语言文法
    实验一
    词法分析
    py中文词频统计
    py字符串练习
    py画了个国旗
    熟悉常用的Linux操作
    大数据概述
    实验三、 递归下降分析程序实验
    简易c语言LL(1)文法
  • 原文地址:https://www.cnblogs.com/Leechg/p/4802764.html
Copyright © 2011-2022 走看看