当年老夫手写的cookie
前言
留来来只为了回忆,旧博客迁移。
正文
/**
* Created by OC on 20xx/8/27.
*/
function setCookie(name,value,expires,path)
{
var cookieText=encodeURIComponent(name)+"="+encodeURIComponent(value);
if(expires instanceof Date)
{
cookieText+=";expires"+expires;
}
if(path)
{
cookieText+=";path="+path;
}
document.cookie=cookieText;
return decodeURIComponent(document.cookie);
}
function getCookie(name)
{
var cookie=decodeURIComponent(document.cookie);
var arr=cookie.split(";");
for(var i=0;i<arr.length;i++)
{
var attr2=arr[i].split("=");
if(attr2.length>=2)
{
if(attr2[0]==name)
{
return attr2[1];
}
}
}
return "";
}
function removeCookie(name)
{
document.cookie=encodeURIComponent(name)+"=expires="+new Date();
}