日期:2014-05-18  浏览次数:20726 次

Javascript实现动态图标的问题
我希望完成一个动态的图片循环

他运行是弹出   out   of   memory   at   line:27

function   changPIC()
{
document.getElementById( 'mi1 ').src   =   myImage[k].src;
k++;
if(k   ==   9)
{
k   =   0;
}
                  如果我在这里加入一个alert( '1 ');   就可以看到图片的正常循环
setTimeout(changPIC(),2000);
}

以下是完整的代码
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 "   />
<title> Image对象应用 </title>
<script   type= "text/javascript ">
<!--
var   myImage   =   new   Array(9);
for(var   i=0;i <=9;i++)
{
myImage[i]   =   new   Image();
}
myImage[0].src   =   "../PIC/1.jpg ";
myImage[1].src   =   "../PIC/2.jpg ";
myImage[2].src   =   "../PIC/3.jpg ";
myImage[3].src   =   "../PIC/4.jpg ";
myImage[4].src   =   "../PIC/5.jpg ";
myImage[5].src   =   "../PIC/6.jpg ";
myImage[6].src   =   "../PIC/7.jpg ";
myImage[7].src   =   "../PIC/8.jpg ";
myImage[8].src   =   "../PIC/9.jpg ";
myImage[9].src   =   "../PIC/10.jpg ";

var   k   =   0;
function   changPIC()
{
document.getElementById( 'mi1 ').src   =   myImage[k].src;
k++;
if(k   ==   9)
{
k   =   0;
}
setTimeout(changPIC(),2000);
}
//-->
</script>
</head>

<body   onload= "changPIC(); ">
<img   id= "mi1 "   src= "../PIC/1.jpg "   />
</body>
</html>

------解决方案--------------------
setTimeout( "changPIC() ",2000);