Cookie之获设删

 1 //设置COOKIE值
 2 function setCookie(sName,sValue,oExpires,sPath,sDomain,bSecure)
 3 {
 4     var sCookie = sName + "=" + encodeURIComponent(sValue);
 5 
 6     if(oExpires) { sCookie += "; expires=" + oExpires.toString(); }
 7 
 8     if(sPath) { sCookie += "; path=" + sPath; }
 9 
10     if(sDomain) { sCookie += "; domain=" + sDomain; }
11 
12     if(bSecure) { sCookie += "; secure"; }
13 
14     document.cookie = sCookie;
15 }
16 
17 //获取COOKIE值
18 function getCookie(sName)
19 {
20     var sRE = "(?:; )?" + sName + "=([^;]*);?";
21     var oRE = new RegExp(sRE);
22 
23     if(oRE.test(document.cookie)) { return decodeURIComponent(RegExp["$1"]); }
24     else { return null; }
25 }
26 
27 //删除COOKIE值
28 function deleteCookie(sName,sPath,sDomain)
29 {
30     setCookie(sName,"",new Date(0),sPath,sDomain);
31 }

 

posted @ 2017-08-30 11:11  Panxl  阅读(110)  评论(0编辑  收藏  举报