设置cookie
代码如下 | 复制代码 |
function setcookie(name,value,days) { if(days){ var exp = new date(); exp.settime(exp.gettime() + days*24*60*60*1000); document.cookie = name + "="+ escape(value) +";expires="+ exp.togmtstring(); }else{ document.cookie = name + "="+ escape(value); } } |
获取 cookie值
代码如下 | 复制代码 |
function getcookie(name) { var arr = document.cookie.match(new regexp("(^| )"+name+"=([^;]*)(;|$)")); if(arr != null) return unescape(arr[2]); return null; } |
删除cookie
代码如下 | 复制代码 |
function delcookie(name) { var exp = new date(); exp.settime(exp.gettime() - 1); var cval=getcookie(name); if(cval!=null) document.cookie=name +"="+cval+";expires="+exp.togmtstring(); }; |
时间: 2024-09-29 00:03:29