JS设置cookie setcookie getcookie

//获取cookie值
function getCookie(name) 
{ 
    //document.cookie.setPath("/");
    var arr, reg = new RegExp("(^| )"+name+"=([^;]*)(;|$)");
    if(arr=document.cookie.match(reg))
    {
          return unescape(arr[2]); 
    }
    else 
    {
        return null; 
    }
}
 
 
//设置cookie值
function setCookie(name,value) 
{ 
    //document.cookie.setPath("/");
    var hour = 8; 
    var exp = new Date(); 
    exp.setTime(exp.getTime() + hour*60*60*1000); 
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString()+";path=/"; 
}

 

posted on 2020-12-01 10:46  Ben丶大壮  阅读(2845)  评论(0编辑  收藏  举报

导航