首页 > 代码库 > 封装cookie的获取,设置与查找

封装cookie的获取,设置与查找

//获取cookie
function getCookie(key,value){
var c = document.cookie;
var str = key + ‘=‘ + value;
var re = new RegExp(‘(^|\\s)‘+str+‘;?($|\\s)‘);
return re.test(c);
}
//设置cookie
function setCookie(key,val,time){
time = time?time:0;
var data = http://www.mamicode.com/new Date();
data.setDate(data.getDate()+time);
document.cookie = key+‘=‘+val+‘;expires=‘+(time?data:0);
}
//删除cookie
function removeCookie(key,value){
setCookie(key,value,-1);
}

封装cookie的获取,设置与查找