cookie操作

function setCookie(name, value, ms){
    var oDate=new Date();
    oDate = new Date(oDate.getTime()+ms*1000);
    document.cookie=name+'='+encodeURIComponent(value)+';expires='+oDate;
}
function getCookie(name){
    var arr=document.cookie.split('; ');
    var i=0;
    for(i=0;i<arr.length;i++){
        //arr2->['username', 'abc']
        var arr2=arr[i].split('=');
        if(arr2[0]==name){
            var getC = decodeURIComponent(arr2[1]);
            return getC;
        }
    }
    return '';
}
function removeCookie(name){
    setCookie(name, '', -1);
}

 

posted @ 2018-01-02 10:45  邹柯  阅读(101)  评论(0编辑  收藏  举报