我正在尝试设置多个 cookiedocument.cookie
,但不幸的是只有一个被添加。
我知道网上有多个设置此类 cookie 的示例,我遵循了其中之一。但我仍然无法解决这个问题。
我跟着这个link http://www.elated.com/articles/javascript-and-cookies/设置我的cookie。
My Code:
function setCookie(start_time,end_session_time,total_time,flag,count){
var cookie_string = "start_time="+start_time;;
if(end_session_time) {
cookie_string +="; end_session_time="+end_session_time;
}
if(total_time){
cookie_string +="; total_time="+total_time;
}
if(flag){
cookie_string +="; flag="+flag;
}
if(count){
cookie_string +="; count="+count;
}
document.cookie =cookie_string ;
console.log(cookie_string);
console.log("document.cookie ="+ document.cookie);
}
输出:
cookie_string :: start_time=1369926508266; flag=1; count=1
document.cookie =start_time=1369926508266;
添加 cookie 是通过以下方式执行的document.cookie = "name=value"
要添加多个键,您应该执行多次分配
function setCookie(start_time, end_session_time, total_time, flag, count) {
document.cookie = "start_time=" + start_time;
if (end_session_time) {
document.cookie = "end_session_time=" + end_session_time;
}
if (total_time) {
document.cookie = "total_time=" + total_time;
}
if (flag) {
document.cookie = "flag=" + flag;
}
if (count) {
document.cookie = "count=" + count;
}
console.log("document.cookie = " + document.cookie);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)