function writeCookie(name, value, domain, days )
{
var expire = ""; //by default, there is no expiration so the cookie is temporary
var domain = "; domain=" + domain + "; path=/";
//specifying a number of days makes the cookie persistent
if(days)
{
expire = new Date((new Date()).getTime() + days * 24 * 60 * 60 * 1000);
expire = "; expires=" + expire.toGMTString();
}
//set the cookie to the name, value, and expiration date
document.cookie = name + "=" + escape(value) + expire + domain;
}
function readCookie(name){
//find the specified cookie and return its value
var searchName = name + "=";
var cookie = document.cookie.split(';');
for(var i = 0 ; i < cookie.length; i++){
var c = cookie[i];
while(c.charAt(0) == ' ')
c = c.substring(1, c.length);
if(c.indexOf(searchName) == 0)
return c.substring(searchName.length, c.length);
}
return null;
}
function eraseCookie(name){
//erase the specified cookie
writeCookie(name,"",""-1);
}
-----------------------------------------------------------------
处理cookie的三个f辅助函数:writeCookie, readCookie, clearCookie
最新推荐文章于 2020-11-22 12:57:00 发布