爱东东

VS.NET,IT,个人,个人网站 爱东东 http://www.idongdong.net

 

JS操作Cookie

function setcookiebyaddseconds(sname,svalue,iseconds)
{
 var d = new Date();
 d.setTime(d.getTime() + iseconds*1000);
 document.cookie=sname + "=" + svalue+" ;expires = "+d.toGMTString();
}
function setcookie(sname,svalue,iyear,imonth,iday,ihour,iminute,isecond)
{
 var d = new Date();
 d.setFullYear(iyear);
 d.setMonth(imonth);
 d.setDate(iday);
 d.setHours(ihour);
 d.setMinutes(iminute);
 d.setSeconds(isecond);
 document.cookie=sname + "=" + svalue+" ;expires = "+d.toGMTString();
}
function getcookie(sname)
{
 var s=sname + "=";
 begin=document.cookie.indexOf(s);
 if(begin != -1)
 {
  begin+=s.length;
  end = document.cookie.indexOf(";",begin);
  if (end == -1) end = document.cookie.length;
  return document.cookie.substring(begin,end);
 }
 else
 {
  return "";
 }
}
function delcookie(sname)
{
 document.cookie=sname + "=;expires = Thu,01-Jan-70 00:00:00 GMT";
}

posted on 2007-04-07 13:54  爱东东  阅读(377)  评论(0编辑  收藏  举报

导航