我正在尝试为一个网站制作 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
1 回答
芜湖不芜
TA贡献1796条经验 获得超7个赞
从记录的 cookie 中,我能够确定系统只读取了其中的一部分。从这里我现在可以编辑它来工作。感谢 Rinkesh Golwala!你只是让我免于数小时的直接调试,但无济于事。
你真的不需要再评论了。
添加回答
举报
0/150
提交
取消