Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要能够使用 Javascript 设置一个 cookie 并让它在每个星期六过期,但不知道从哪里开始。
var now = new Date(); var day = now.getDay();
文档.cookie =
首先,您必须以这种方式定义下周六。
var nextSaturday = new Date(); nextSaturday.setDate(nextSaturday.getDate() + (6 + 7 - nextSaturday.getDay()) % 7);
如果你console.log(nextSaturday)它会给你下周六的日期。然后你可以像这样存储你的cookie:
console.log(nextSaturday)
document.cookie = "myCookie=ok; expires=" + nextSaturday;