设置和获取cookie

function setCookie(name,value){

    document.cookie = name + "=" + encodeURI(value);

}

 

function getCookie(name){

    var str = document.cookie;

    if(!str || str.indexOf(name + "=") < 0){

       return null;

    }

    var cookies = str.split(";");

    for(var i=0; i < cookies.length; i++){

       var cookie = cookies[i];

       if(cookie.indexOf(name + "=") == 0){

           var value = cookie.substring(name.length + 1);

           return decodeURI(value);

       }

    }

    return null;

}

posted on 2014-12-26 21:08  笨'小孩  阅读(178)  评论(0编辑  收藏  举报

导航