js 读写删除cookies操作函数
function setcookie(name,value)//两个参数,一个是cookie的名子,一个是值
{
var days = 30; //此 cookie 将被保存 30 天
var exp = new date(); //new date("december 31, 9998");
exp.settime(exp.gettime() + days*24*60*60*1000);
document.cookie = name + "="+ escape (value) + ";expires=" + exp.togmtstring()+ "; path=" + "/" ;
}
function getcookie(name)//取cookies函数
{
var arr = document.cookie.match(new regexp("(^| )"+name+"=([^;]*)(;|$)"));
if(arr != null) return unescape(arr[2]); return null;
}
function delcookie(name)//删除cookie
{
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-13 04:40:21