我有一个程序,其中一个HTML按钮调用了一个jQuery函数(称其为funcOne)。该函数又调用了一个递归函数(称其为funcTwo),该函数会更改DOM中的某些CSS。funcTwo包含两个setTimeout()调用以延迟CSS更改,从而创建一种闪烁效果。
funcOne大致如下:
function funcOne(stringOfNumbers){
//This function does some other stuff that does not interfere with funcTwo
someUnrelatedFunction();
funcTwo(time);
return;
}
funcTwo的代码大概长这个样子:
function funcTwo(time){
if(time == ""){return true;}
var delay = time.charAt(0);
var numDelay = parseInt(delay);
setTimeout(function(){
$("#container").css("background-color", "white");
console.log("Changed to white");
}, 1000); //Arbitrary delay
setTimeout(function(){
$("#container").css("background-color", "black");
console.log("Changed to black");
}, numDelay); //Variable delay
time = time.substr(1);
return funcTwo(time);
}
控制台显示了两个信息,所以我知道脚本正在运行。我没有收到任何堆栈溢出错误。 然而,两种延迟(任意和变量)都没有运行。#container立即变成黑色。
我做错了什么?任何帮助都将不胜感激。