封装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 = new Date();
data.setDate(data.getDate()+time);
document.cookie = key+'='+val+';expires='+(time?data:0);
}
//删除cookie
function removeCookie(key,value){
setCookie(key,value,-1);
}

posted @ 2017-03-18 21:54  zhouyia~  阅读(132)  评论(0编辑  收藏  举报