帮我看看这个问题,有关setTimeout的
我想写一段动态变换窗口背景的代码,想要达到的目的是,1、随机挑选图片做为背景;2、变更背景的时间间隔在一定时间内是随机的;3、清屏方式是随机的(有多种清屏方式)。现在的问题是,因为在代码中用了几个setTimeout,不知何处出错,导致程序运行了一阵子之后,也就是实现了上述功能若干次后,就不再变更背景了。我怀疑是setTimeout太多的缘故,但不知如何修改,请帮忙看看。基本框架如下:
<script language="JavaScript">
....
var nFirst=1; //是不是第一次运行
var nClearID=0;
var nSysTimeoutID;
var nClearTimeoutID;
function RandomChangeBackPic()
{
....
if(nFirst) //如果是第一次运行
{
....
nFirst=0;
nSysTimeoutID=window.setTimeout("RandomChangeBackPic()",Math.round(Math.random()*1000*60*nTimeInterval));
return;
}
....
//nClearID随机赋值
if(nClearID==1) //清屏方式1
{
....
ClearScreen1();
}
....
if(nClearID==N) //清屏方式N
{
....
ClearScreenN();
}
}
function ClearScreen1()
{
if(nSysTimeoutID)
window.clearTimeout(nSysTimeoutID);
if(....)
{
....
nClearTimeoutID=window.setTimeout("ClearScreen1()",1);
}
else
{
window.clearTimeout(nClearTimeoutID);
....
nSysTimeoutID=window.setTimeout("RandomChangeBackPic()",Math.round(Math.random()*1000*60*nTimeInterval));
}
}
....
function ClearScreenN()
{
if(nSysTimeoutID)
window.clearTimeout(nSysTimeoutID);
if(....)
{
....
nClearTimeoutID=window.setTimeout("ClearScreenN()",1);
}
else
{
window.clearTimeout(nClearTimeoutID);
....
nSysTimeoutID=window.setTimeout("RandomChangeBackPic()",Math.round(Math.random()*1000*60*nTimeInterval));
}
}
....
window.onload=RandomChangeBackPic;
</script>