小编And*_*res的帖子

在 Javascript Cookie 中设置了重复键

我的问题是 JS cookie 设置了两个“viewmore”键。此处“viewmore”设置为true 和false。谁能帮忙诊断一下!?

 > document.cookie
    "viewmore=true; SESSID=fjs0fmojglrih7; viewmore=false; user=1"
Run Code Online (Sandbox Code Playgroud)

“viewmore”键不应该被覆盖并且不应该用不同的值复制吗?

无效的代码:

document.cookie = "viewmore=false";
document.cookie = "viewmore=true";
Run Code Online (Sandbox Code Playgroud)

有效的代码:需要一个到期集

var now = new Date();
now.setTime(now.getTime() + 1 * 3600 * 1000);

document.cookie = "viewmore=false; expires=" + now.toUTCString() + "; path=/";
document.cookie = "viewmore=true; expires=" + now.toUTCString() + "; path=/";
Run Code Online (Sandbox Code Playgroud)

html javascript cookies duplicates

6
推荐指数
1
解决办法
1367
查看次数

标签 统计

cookies ×1

duplicates ×1

html ×1

javascript ×1