|
-
- //设置字符串类型的本地缓存
- function setStorage(objName, objValue){
- var sto = window.localStorage;
- if (sto)
- sto.setItem(objName, objValue);
- }
- //读取字符串类型的本地缓存
- function getStorage(objName){
- var ret = '';
- var sto = window.localStorage;
- if (sto)
- ret = sto.getItem(objName);
- return ret;
- }
-
- //清除本地缓存,如没指定名称则为清空所有缓存
- function clearStorage(objName){
- var sto = window.localStorage;
- if (sto) {
- if (objName)
- sto.removeItem(objName);
- else
- sto.clear();
- }
- }
- //设置Json类型的本地缓存
- function setStorJson(objName, json){
- if (json)
- setStorage(objName, JSON.stringify(json));
- }
- //读取Json类型的本地缓存
- function getStorJson(objName){
- var ret = null;
- var str = getStorage(objName);
- if (str)
- ret = JSON.parse(str);
- return ret;
- }
|