导航

Cookie

Posted on 2018-03-25 13:16  小飞博客  阅读(140)  评论(0编辑  收藏  举报
 1 //设置Cookie
 2 function setCookie(name,value,iDay){
 3     var oDate=new Date();
 4     oDate.setDate(oDate.getDate()+iDay);
 5     document.cookie=name+'='+value+';expires='+oDate;
 6 }
 7 //获取Cookie
 8 function getCookie(name){
 9     var arr=document.cookie.split('; ');
10     for(var i=0;i<arr.length;i++){
11         var arr2=arr[i].split('=');
12         if(arr2[0]==name){
13             return arr2[1];
14         }
15     }
16     return '';        
17 }
18 //删除Cookie
19 function deleteCookie(name){
20     setCookie(name,1,-1);
21 }