当前位置: 代码迷 >> JavaScript >> JS:cookies 存、取、剔除实例
  详细解决方案

JS:cookies 存、取、剔除实例

热度:450   发布时间:2012-11-26 11:48:50.0
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 }
  相关解决方案