如果我"body onload="varname=setInterval etc, etc""
最终同时setInterval
运行两个事件,如果我得到"overload == true"
它并不会重置ketchCount
并且它不会更新数组中的图片,它只会启动setInterval
并从那里开始工作。我知道我很新,但我会很感激任何帮助!
ketchupArray=new Array();
ketchupArray[0] = new Image(192, 168);
ketchupArray[0].src = "./pictures/levels/nothing.jpg?";
ketchupArray[1] = new Image(192, 168);
ketchupArray[1].src = "./pictures/levels/lowest.jpg?";
ketchupArray[2] = new Image(192, 168);
ketchupArray[2].src = "./pictures/levels/low.jpg?";
ketchupArray[3] = new Image(192, 168);
ketchupArray[3].src = "./pictures/levels/medium.jpg?";
ketchupArray[4] = new Image(192, 168);
ketchupArray[4].src = "./pictures/levels/high.jpg?";
ketchupArray[5] = new Image(192, 168);
ketchupArray[5].src = "./pictures/levels/highest.jpg?";
overload = false;
ketchCount = 0;
var lessCount;
var overCount;
var lessCountVar;
function overFunction()
{
overload == false;
ketchCount == 0;
document.getElementById("ketchupLevel").src = ketchupArray[ketchCount].src;
lessCountVar=setInterval(function(){lessCount()},5000);
}
function lessCount()
{
if (ketchCount == 0)
{
return;
}
ketchCount--;
document.getElementById("ketchupLevel").src = ketchupArray[ketchCount].src;
}
function moreKetchup()
{
if (overload == true)
{
return;
}
ketchCount++;
document.getElementById("ketchupLevel").src = ketchupArray[ketchCount].src;
if (ketchCount == 5)
{
overload == true;
clearInterval(lessCountVar);
overCount=setTimeout(function(){overFunction()},5000);
}
}
function lessKetchup()
{
if (overload == true)
{
return;
}
else if (ketchCount == 0)
{
return;
}
ketchCount--;
document.getElementById("ketchupLevel").src = ketchupArray[ketchCount].src;
}