js获取cookies的方法

function getCookies() {
    var cookies = document.cookie.split(';');
    var cookieObj = {};
    for (var i = 0; i < cookies.length; i++) {
        var cookie = cookies[i].trim();
        var keyValue = cookie.split('=');
        cookieObj[keyValue[0]] = keyValue[1];
    }
    return cookieObj;
}

var cookies = getCookies();
console.log(cookies);


  目录