我在设置Cookie时尝试添加变量但没有运气。已创建cookie,但未传递该值,它显示为+ content +
function createCookie(name, value, expires, path, domain) {
var cookie = name + "=" + value + ";";
if (expires) {
// If it's a date
if(expires instanceof Date) {
// If it isn't a valid date
if (isNaN(expires.getTime()))
expires = new Date();
}
else
expires = new Date(new Date().getTime() + parseInt(expires) * 1000 * 60 * 60 * 24);
cookie += "expires=" + expires.toGMTString() + ";";
}
if (path)
cookie += "path=" + path + ";";
if (domain)
cookie += "domain=" + domain + ";";
document.cookie = cookie;
}
function updateCookie(){
var content = "value of cookie";
createCookie("newcookie", "+content+", new Date(new Date().getTime() + 10000));
}
答案 0 :(得分:0)
我想你想要
var content = "value of cookie";
createCookie("newcookie", content , new Date(new Date().getTime() + 10000));