JS:cookies 存、取、删除实例

 

function SetCookie(name,value)
02 {
03 var Days = 1;
04 var exp = new Date();
05 exp.setTime(exp.getTime() + Days*24*60*60*1000);
06 document.cookie = name + "=" + escape (value) + ";expires=" + exp.toGMTString();
07 }
08 function getCookie(name) //取cookies函数
09 {
10 var arr = document.cookie.match( new RegExp( "(^| )" +name+ "=([^;]*)(;|$)" ));
11 if (arr != null ) return unescape(arr[2]); return null ;
12    
13 }
14 function delCookie(name) //删除cookie
15 {
16 var exp = new Date();
17 exp.setTime(exp.getTime() - 1);
18 var cval=getCookie(name);
19 if (cval!= null ) document.cookie= name + "=" +cval+ ";expires=" +exp.toGMTString();
20 }

你可能感兴趣的:(Cookies)