zoukankan      html  css  js  c++  java
  • Javascript Cookie小插件

    var ManagerCookie = function(){
        //添加cookie
        function addCookie(key,value,time,path){
            key = encodeURI(key);
            value = encodeURI(value);
            var _expires = new Date();
            time = time ? time : 7;
            _expires.setTime(_expires.getTime() + time*3600*24);
            path = path?path:"/";
            path = ";path="+path;
            var expires = ";expires="+_expires.toUTCString();
            document.cookie = key+"="+value+path+expires;
        };
        //获取cookie
        function getCookie(key){
            var value = "";
            key = encodeURI(key);
            var allCookies = document.cookie;
            key = key + "=";
            var pos = allCookies.indexOf(key);
            if(pos!=-1){
                var start = pos+key.length;
                var end = allCookies.indexOf(";",start);
                //只存在一个cookie
                if(end == -1){
                    end = allCookies.length;
                }
                value = allCookies.substring(start,end);
            };
            return decodeURI(value);
        };
        //删除cookie
        function deleteCookie(key,path){
            key = encodeURI(key);
            path = path?path:"/";
            path = ";path="+path;
            var _expires = new Date(0);
            var expires = ";expires="+_expires.toUTCString();
            document.cookie = key + "=" + path +expires;
        }
        return {
            addCookie:addCookie,
            deleteCookie:deleteCookie,
            getCookie:getCookie
        }
        }();
  • 相关阅读:
    async 和 await
    C#中lock死锁
    Attribute特性
    数据库优化
    EF(ORM)
    依赖注入
    面向接口编程
    EF乐观锁与悲观锁
    为什么要使用RESTFUL风格?
    cloudsim 3.0.3下载与安装教程
  • 原文地址:https://www.cnblogs.com/Darlietoothpaste/p/6739664.html
Copyright © 2011-2022 走看看