0

我正在测试我的 ASP 代码,并让处理程序正确触发,但是在执行我的 javascript 函数时,它给出了一个未定义的错误。

使用 ASP 时,是否会出现 Javascript 未定义的回发或类似边缘状态的情况?

为了测试,我的测试是这样的:

<asp:textbox runat="server" onchange="alert('this is a test'); numsOnly();"></asp:textbox>

这可能是语法问题吗?我应该说 onchange="return numsOnly();" 反而?警报显示它确实触发了,但函数 numsOnly(); 在页面头部定义

4

1 回答 1

0

我注意到我有以下代码行:

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 帮助我指出方向的人,因为最终我正在寻找一些东西,并注意到一个智能感知错误,这证实了他们所说的话。

于 2012-06-18T20:32:52.323 回答