/***********************储存数据*******************************************************/
///设置
function setLoc(name, value) {
return localStorage.setItem(name, value);
}
//获取
function getLoc(name) {
return localStorage.getItem(name);
}
//删除
function deleteLoc(name) {
localStorage.removeItem(name);
}
function qingKongLoc() { localStorage.clear(); }
//设置session
function setSes(name, value) {
sessionStorage.setItem(name, value);
}
function getSet(name) { return sessionStorage.getItem(name); }
function deleteSes(name) { sessionStorage.removeItem(name); }
function qingKongSes() { sessionStorage.clear(); }
/**
*设置Cooke
*@param {string}name 欲设置的键名
*@param {string|int}value 对应键名的值
*@param {int}[Days] 设置COOKIE的有效时间,单位:天 可选参数,默认30天
*/
function setCookie(name,value,Days){
if(!name||!value) return;
var Days=Days ?Days : 30;//默认30天
var exp = new Date();
exp.setTime(exp.getTime() + Days*24*60*60*1000);
document.cookie = name + "="+ encodeURIComponent(value) +";expires="+ exp.toUTCString();
}
/**
*获取Cookie指定键的值,没找到返回null
*/
function getCookie(name){
var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
if(arr != null) return decodeURIComponent(arr[2]);
return null;
}
/**
*删除指定键名的Cookie
*@param {string} name 指定键名
*/
function deleteCookie(name) {
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval = getCookie(name);
if (!cval) document.cookie = name + "=" + cval + ";expires=" + exp.toUTCString();
}