localStorage의 추가 삭제 확인 봉인 함수

2166 단어
(function (win,doc) {
var GD16 = {
/**
* 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
*/
rmItem: function (val) {
if (val) {
win.localStorage.removeItem(val);
} else {
var json = window.localStorage;
for (var i in json) {
win.localStorage.removeItem(i);
}
}
},
/**
* cookie| cookie| cookie
*/
setCookie: function (name, value, time) {
var d = new Date(new Date().getTime() + time * 1000).toGMTString();
document.cookie = '' + name + '=' + value + ';expires=' + d;
},
/**
* cookie
* @param name
* @returns {string}
*/
getCookie: function (name) {
var arr = document.cookie.split('; ');
var value = '';
for (var i = 0, len = arr.length; i < len; i++) {
if (arr[i].split('=')[0] == name) {
value = arr[i].split('=')[1];
break;
}
}
return value;
}
};
win.GD16 = GD16;
})(window,document);

다음으로 전송:https://www.cnblogs.com/deng-00/p/6928658.html

좋은 웹페이지 즐겨찾기