过去几个小时我一直在尝试调试这个 Javascript。第一个 if 块执行得很好,但是当我尝试执行第二个 if 语句时,我收到“未定义不是函数”错误消息。
我检查了 JSLint 和 JSHint,并尝试注释掉我的部分代码无济于事。任何帮助将非常感激。
var nimbus_char_count = 0;
var nimbus_line_count = 1;
var i = 2;
var j = 2;
//This block executes fine
function set_char(increment) {
//Test success cases
if (increment === 1 && nimbus_char_count < 3) {
nimbus_char_count = nimbus_char_count + 1;
$("#nimbus_char" + (nimbus_char_count - 1)).addClass("nimbus_drop");
} else if (increment === -1 && nimbus_char_count > 0) {
nimbus_char_count = nimbus_char_count - 1;
$("#nimbus_char" + nimbus_char_count).removeClass("nimbus_drop");
} else {
nimbus_flash_red();
}
}
//This block throws a "undefined is not a function"
function set_lines(increment) {
if (increment === 1 && nimbus_line_count < 4) {
nimbus_line_count = nimbus_line_count + 1;
for (i = 2; i >= 0; i = i - 1) {
$().getElementsById("#nimbus_char").addClass("nimbus_drop" + i);
}
} else if (increment === -1 && nimbus_char_count > 1) {
nimbus_char_count = nimbus_char_count - 1;
for (j = 2; j >= 0; j = j - 1) {
$().getElementsById("#nimbus_char").addClass("nimbus_drop" + j);
}
} else {
nimbus_flash_red();
}
}