如何使用值"将=字符更改为"

时间:2014-04-27 08:09:19

标签: javascript jquery html cookies

我从另一个问题得到了这个:

document.getElementById('value').innerHTML=listCookies()
function listCookies() {
    var theCookies = document.cookie.split(';');
    var aString = '';
    for (var i = 1 ; i <= theCookies.length; i++) {
        aString += ' ' + theCookies[i-1] + "\n";
    }
    return aString;
}

它会说:

cookie=value

我怎么能这样做:

cookie with the value 4

1 个答案:

答案 0 :(得分:2)

function listCookies() {
    var theCookies = document.cookie.split(';');
    var aString = '';
    for (var i = 0 ; i < theCookies.length; i++) {
        aString += ' ' + theCookies[i].replace('=', ' with the value ') + "\n";
    }
    return aString;
}