我希望下面的代码设置root的路径,我知道我必须设置/作为路径值,但这不是我的代码,我不熟悉Javascript!
function setCookie(name, value, expires, path, domain, secure){
document.cookie= name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}
我已尝试编辑如下代码,但未成功。
setCookie(name, value, expires, path, domain, secure){
document.cookie= name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path="/") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}
答案 0 :(得分:14)
更改为
function setCookie(name, value, expires, path, domain, secure){
document.cookie= name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
("; path=/") + //you having wrong quote here
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}