Cookie

创建 cookie
 function SetCookie(cname, cvalue,exdays){
            var d=new Date();
            d.setTime(d.getTime()+(exdays)*24*60*60*1000);
            var expires="expires="+d.toUTCString();
            document.cookie=cname+"="+cvalue+";"+expires;
        }
SetCookie("name","张三", 1)
读取cookie
 function getcookies(cname) {
           var arrstr = document.cookie.split("; ");
           for (var i = 0; i < arrstr.length; i++); {
               var temp = arrstr[i].split("=");
               if (temp[0] == cname) {
                   return temp[1];
               }
           }
           return "该cookies不存在";
       }
getcookies("name")
删除cookie
function clearCookie(name){
         setCookie(name,"",-1)
}
clearCookie("name");//删除名为“name”的cookie

 

 

posted @ 2018-01-15 09:05  你的斗志并没有失去  阅读(121)  评论(0编辑  收藏  举报