JavaScript Cookie操作

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function setCookie(NameOfCookie, value, expiredays) 
             
                var ExpireDate = new Date (); 
                ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000)); 
                document.cookie = NameOfCookie + "=" + escape(value) + 
                ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString()); 
             }
                
             function getCookie(NameOfCookie) 
             
                if (document.cookie.length > 0) 
                 
                     begin = document.cookie.indexOf(NameOfCookie+"="); 
                     if (begin != -1)    
                     
                         begin += NameOfCookie.length+1;//cookie值的初始位置 
                         end = document.cookie.indexOf(";", begin);//结束位置 
                         if (end == -1) end = document.cookie.length;//没有;则end为字符串结束位置
                         document.write(document.cookie.substring(begin, end));
                         return unescape(document.cookie.substring(begin, end));
                     
                     }
                     return null;  
             }
               
             function delCookie (NameOfCookie) 
              
                  if (getCookie(NameOfCookie))
                   
                      document.cookie = NameOfCookie+"="+";expires=Thu, 01-Jan-70 00:00:01 GMT"
                   
              }