/*
name是cookie的名字,也就是服务器端cookie的键
value是你cookie里面存的值
days是你想要多少天后过期
*/
function ppkCreate(name,value,days) {//写入一个cookie,
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
/*
name输入cookie的键值读取出cookie的value
*/
function ppkRead(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
/*
name输入cookie的键值,是让cookie失效也就是过期
*/
function ppkErase(name){
ppkCreate(name,'',-1);
}
ppkCreate("come",new Date().getTime(),1);//设置一个cookie键为:come,值为当前时间,过期时间为1天
alert(ppkRead("come"));//取值
ppkErase("come");//过期
alert(ppkRead("come"));//取值