我正在尝试为一个网站制作 cookie,以便为每个页面保存我是否处于黑暗模式。当我在开发控制台中激活该功能时,我不断在控制台中收到错误消息,我迅速输入以确保一切正常。
我已经尝试修改这些功能,但没有任何效果。我对 JavaScript 很陌生,我真的没有经验。
const cookies = document.cookie;
function darkmodeCookieEdit () {
if (cookies === "d = 0; path = /; expires: Tue, 16 Jun 2099 00:00:00 GMT;") {
//Edit Cookie
document.cookie = "d =; path = /; expires: Thu, 01 Jan 1970 00:00:00 GMT;";
document.cookie = "d = 1; path = /; expires: Tue, 16 Jun 2099 00:00:00 GMT;";
//Edit Page
navbar.style.background = "#2b2b2b";
navbar.style.color = "#ffffff";
content.style.background = "#242323";
content.style.color= "#ffffff"
console.log(cookies);
} else if (cookies === "d = 0; path = /; expires: Tue, 16 Jun 2099 00:00:00 GMT;") {
//Edit Cookie
document.cookie = "d =; path = /; expires: Thu, 01 Jan 1970 00:00:00 GMT;";
document.cookie = "d = 0; path = /; expires: Tue, 16 Jun 2099 00:00:00 GMT;"
console.log(cookies);
} else {
document.cookie = "d =; path = /; expires: Thu, 01 Jan 1970 00:00:00 GMT;";
document.cookie = "d = 0; path = /; expires: Tue, 16 Jun 2099 00:00:00 GMT;";
console.error("Darkmode cookies broken.");
console.log(cookies);
}
}
无论我将函数输入开发控制台多少次,它似乎总是落到最后。 https://i.stack.imgur.com/gVCgi.png
芜湖不芜
相关分类