我注意到我有以下代码行:
if (x[11] == "top" && x[12] == "left") { $("#toggle_1").attr("checked", "true"); }
else if (x[12] == "top" && x[11] == "middle") { $("#toggle_2").attr("checked", "true"); }
else if (x[12] == "top" && x[11] == "right") { $("#toggle_3").attr("checked", "true"); }
else if (x[12] == "middle" && x[11] == "left") { $("#toggle_4").attr("checked", "true"); }
else if (x[12] == "middle" && x[11] == "middle") { $("#toggle_5").attr("checked", "true"); }
else if (x[12] == "middle" && x[11] == "right") { $("#toggle_6").attr("checked", "true"); }
else if (x[12] == "bottom" && x[11] == "left") { $("#toggle_7").attr("checked", "true"); }
else if (x[12] == "bottom" && x[11] == "middle") { $("#toggle_8").attr("checked", "true"); }
else if (x[12] == "bottom" && x[11] == "right") { $("#toggle_9").attr("checked", "true"); }
else alert("None of the alignments were matched");
我还注意到警报声明已被注释掉,因为我现在不需要一直知道该信息。它看起来像:
else if (x[12] == "bottom" && x[11] == "right") { $("#toggle_9").attr("checked", "true"); }
else //alert("None of the alignments were matched");
它未能通过 javascript 测试,因为它正在寻找执行不存在的东西,并将右括号作为代码的一部分读取,并且出现错误。
通过添加以下 2 个字符 { 和 } 可以轻松解决此问题。
else if (x[12] == "bottom" && x[11] == "right") { $("#toggle_9").attr("checked", "true"); }
else { alert("None of the alignments were matched"); }
问题解决了。抱歉这个问题。Will +1 帮助我指出方向的人,因为最终我正在寻找一些东西,并注意到一个智能感知错误,这证实了他们所说的话。