1 //写cookies
2 function setCookie(name,value)
3 {
4 var Days = 30;
5 var exp = new Date();
6 exp.setTime(exp.getTime() + Days*24*60*60*1000);
7 document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
8 }
9
10 //读取cookies
11 function getCookie(name)
12 {
13 var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
14 if(arr=document.cookie.match(reg)){
15 return unescape(arr[2]);
16 }else{
17 return null;
18 }
19 }
20
21 //删除cookies
22 function delCookie(name)
23 {
24 var exp = new Date();
25 exp.setTime(exp.getTime() - 1);
26 var cval=getCookie(name);
27 if(cval!=null)
28 document.cookie= name + "="+cval+";expires="+exp.toGMTString();
29 }