IF声明不起作用

时间:2011-06-06 20:49:55

标签: javascript html

对不起,如果我做了一些非常愚蠢的事情,但是我不能让这个IF声明工作......

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

通过调试我可以看到所有cookie变量都是正确的,但IF语句似乎没有读取值?前两个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);
}

1 个答案:

答案 0 :(得分:4)

所有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";
...