前端存取cookie

1、存cookie

document.cookie="user_phone="+loginMake1Value;//存手机号码cookie
//'
user_phone'为cookie名;‘loginMake1Value’为自定义的cookie值

2、取cookie

function getCookie(key) {
    var strCookie=document.cookie;
    //将多cookie切割为多个名/值对
    var arrCookie=strCookie.split("; ");
    for (var i = 0; i < arrCookie.length; i++) {
        var tmp = arrCookie[i].split('=');
        if (tmp[0] == key) {
            return tmp[1];
        }
    }
}
var shareUserPhone=getCookie('user_phone');//取用户电话

 

posted @ 2018-04-16 19:49  Candy-Yao  阅读(595)  评论(0编辑  收藏  举报