gpt4 book ai didi

javascript - IF 语句不起作用

转载 作者:行者123 更新时间:2023-11-30 10:49:39 26 4
gpt4 key购买 nike

很抱歉,如果我正在做一些非常愚蠢的事情,但我无法让这个 IF 语句工作...

它的作用是检查 cookie 中的某些值,设置组合框默认值。

通过调试我看到所有的cookie变量都是正确的,但是if语句好像没有读到值?前两个 IF 正常工作,但最后一个 else-if 不工作。

非常感谢任何帮助,谢谢

function checkBody() {
var cookie1 = readCookie("Text Colour");
textCol = cookie1 ? cookie1 : "#444";

var cookie2 = readCookie("Background Colour");
backCol = cookie2 ? cookie2 : "white";

var cookie3 = readCookie("Link Colour");
linkCol = cookie3 ? cookie3 : "#0424B5";

var cookie4 = readCookie("Heading1 Colour");
heading1Col = cookie4 ? cookie4 : "#0424B5";

var cookie5 = readCookie("Headings Colour");
headingsCol = cookie5 ? cookie5 : "#99975A";

var element = document.getElementById('colours');
if(textCol == cookie1 && backCol == cookie2)
element.value = "#444,white,#0424B5,#0424B5,#99975A";
else if(textCol == cookie1 && backCol == cookie2)
element.value = "black,yellow,black,black,black";
else if(textCol == cookie1 && backCol == cookie2)
element.value = "black,#87CEFA,black,black,black";

bodyStyle(textCol,backCol,linkCol,heading1Col,headingsCol);
}

最佳答案

所有的 if 都是一样的。后两者从未达到。

...
else if(textCol == cookie1 && backCol == cookie2)
element.value = "black,yellow,black,black,black";
else if(textCol == cookie1 && backCol == cookie2)
element.value = "black,#87CEFA,black,black,black";
...

关于javascript - IF 语句不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6257879/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com