JavaScript写的cookie类(2)

2008-02-23 07:50:27来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折


return false;
}
}
var dt=new Date();
dt.setTime(dt.getTime() this.expires);
document.cookie=this.key "=" this.value ";expires=" dt.toGMTString();
this.init();
return true;
}
this.get=function(key)//取得名为key的cookie的值
{if(key==""||key.match(/[,; ]/))
{alert("请正确设置欲查找的cookie名称!")
return false;
}
var cookie=document.cookie;
var start=cookie.indexOf(key "=");
if(start==-1)
{alert("欲查找的cookie不存在!")
return false;
}
var end=cookie.indexOf(";",start);
if(end==-1)
end=cookie.length;
var getCookie=cookie.substring(start key.length 1,end);
alert("cookie:" key "的值为" getCookie);
return getCookie;
}
this.showAll=function(){alert("共有以下cookie对:\n" document.cookie.split(";").toString().replace(/,/g,"\n"));}//显示所有cookie
this.del=function(key)//删除名为key的cookie
{if(key==""||key.match(/[,; ]/))
{alert("请正确设置欲删除的cookie名称!")
return false;
}
var dt=new Date();
dt.setTime(dt.getTime());
document.cookie=key "=eyunDelete;expires=" dt.toGMTString();
this.init();
return true;
}
this.destroy=function()//销毁所有cookie
{var dt=new Date();
dt.setTime(dt.getTime());
while(document.cookie!="")
document.cookie=document.cookie ";expires=" dt.toGMTString();
this.init();
return true
}
}
var cookieTest=new eyunCookie()
function settest()
{cookieTest.key="test"
cookieTest.value="ok"
cookieTest.expires=31536000000
cookieTest.set()
}
</script>
<input type=button onclick=cookieTest.showAll() value=read><input type=button onclick="cookieTest.set('a','test',31536000000)" value=setA><input type=button onclick="settest();" value=setTest><input type=button onclick="cookieTest.destroy()" value=clear><input type=button onclick=cookieTest.get("test") value=gettest><input type=button onclick=cookieTest.get("a") value=geta><input type=button onclick=cookieTest.set("test",1,31536000000) value=resetTest><input type=button onclick=cookieTest.del("test") value=delTest>

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:mp3的自动连续播放以及探测是否可以播放、并对可以播放的结果进

下一篇:判断file框选择的是否为图片