87,993
社区成员
发帖
与我相关
我的任务
分享
function addCookie(objName,objValue,objHours)
{
//已经有此名时,不添加
if(document.cookie.toString().indexOf(objName)!=-1)
{
return -1;
}
var str=objName+"="+escape(objValue.toString());
if(objHours>0)
{
var date=new Date();
var ms=objHours*3600*1000;
date.setTime(date.getTime()+ms);
str+=";expires="+date.toGMTString();
}
document.cookie=str;
//alert(document.cookie.toString().indexOf(objName)==-1);
}
function getCookie(objName)
{
if(document.cookie==null || document.cookie.toString().indexOf(objName)==-1)
{
// alert(document.cookie.toString().indexOf(objName)==-1);
return null;
}
var str=document.cookie.toString();
var begin=str.indexOf(";");
if(begin==-1)
{
return unescape(str.substring(str.indexOf("=")+1));
}
var v=unescape(str.substring(str.indexOf("=")+1,begin));
return v;
}
function delCookie(objName)
{
var date=new Date();
date.setTime(date.getTime()-10000);
document.cookie=objName+"=a;expires="+date.toGMTString();
}