1.通过设置document.cookie
添加一个cookie: addCookie(name,value,expireTime)
<script languae="javascirpt" type="text/javascript">
<!--
function addCookie(name,value,expireTime)
{
var cookieString=name+"="+escape(value);
if(expireTime>0)
{
var date=new Date();
date.setTime(date.getTime()+expireTime*3600*1000);
cookieString=cookieString+"; expire="+date.toGMTString();
}
document.cookie=cookieString;
}
//-->
</script>
2.获取指定名称的cookie值:getCookie(name)
<script languae="javascirpt" type="text/javascript">
<!--
function getCookie(name){
var strCookie=document.cookie;
var arrCookie=strCookie.split("; ");
for(var i=0;i<arrCookie.length;i++)
{
var arr=arrCookie[i].split("=");
if(arr[0]==name) return arr[1];
}
return "";
}
//-->
</script>
3.删除指定名称的cookie:delCookie(name)
<script languae="javascirpt" type="text/javascript">
<!--
function delCookie(name){
var date=new Date();
document.cookie=name+"=v; expire="+date.toGMTString();
}
//-->
</script>
posted on 2008-07-20 23:38
长春语林科技 阅读(264)
评论(0) 编辑 收藏 所属分类:
js