zoukankan      html  css  js  c++  java
  • localstorage-前端存储

    (function (win,doc) {
    var local_storage = {
    //创建localstorage @param argument json || string
    items: function (argument) {
    if (typeof argument == 'object') { //创建
    for (var i in argument) {
    win.localStorage.setItem(i, argument[i]);
    }
    } else if (typeof argument == 'string') { //获取
    return win.localStorage.getItem(argument);
    } else {
    return console.error('参数只能是json或者string');
    }
    },
    //删除localstorage @param val string || null
    rmitems: function (val) {
    if (val) {
    win.localStorage.removeItem(val);
    } else {
    var json = window.localStorage;
    for (var i in json) {
    win.localStorage.removeItem(i);
    }
    }
    }
    }
    win.local_storage =local_storage ;
    })(window,document);
    用个js来装载,要用的时候直接调用还是很方便的,用json格式来装载,直接在另一个js里调用:如
    local_storage .items({name:'哈哈',age:12});就可以直接用把长的代码简单化
  • 相关阅读:
    (57)C# frame4 调用frame2
    (56)C# 读取控制台程序
    (55)C# windows 消息
    (54) C# 调用 kernel32.dll
    (53)C# 工具
    C++ hello world
    postgresql时间处理
    ext中grid根据数据不同显示不同样式
    log4j入门
    敏感数据加密
  • 原文地址:https://www.cnblogs.com/kongweimei/p/6912552.html
Copyright © 2011-2022 走看看