发布网友 发布时间:2022-04-24 18:59
共2个回答
热心网友 时间:2022-04-22 18:51
按我的来:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>循环播放图片</title>
</head>
<script language=javascript>
var curindex=0;
var timeInterval=2000;
var array = new Array("photo//Chrysanthemum.jpg","photo//Desert.jpg","photo/Hydrangeas.jpg","photo/Jellyfish.jpg","photo/Koala.jpg");
setInterval(circulate,timeInterval);
function circulate(){
var obj=document.getElementById("obj");
if(curindex==array.length-1)
{
curindex=0;
}else{
curindex++;
alert(curindex)
}
obj.src=array[curindex];
}
</script>
<body onload=circulate>
<center><img src="photo/Chrysanthemum.jpg" width="1024" height="768"" border="0" id=obj />
</center>
</body>
</html>追问依旧没有刷新啊
追答兄弟,你看这个:
循环播放图片
var curindex=0;
var timeInterval=2000;
var array = new Array("./1.jpg","./2.jpg","./3.jpg","./4.jpg","./5.jpg");
setInterval(circulate,timeInterval);
function circulate(){
var obj=document.getElementById("obj");
if(curindex==array.length-1)
{
curindex=0;
}else{
curindex++;
}
obj.src=array[curindex];
}
你在你的html所在路径下面,搞几张不同的图片,名字分别为 1.jpg 2.jgp 3.jpg 4.jpg 5.jpg
然后运行我的代码,是肯定可以的,我试过的
热心网友 时间:2022-04-22 20:09
有些语法错误。
var curindex=0;
var timeInterval=2000;
var array = new Array("photo//Chrysanthemum.jpg","photo//Desert.jpg","photo/Hydrangeas.jpg","photo/Jellyfish.jpg","photo/Koala.jpg")
function circulate(){
var obj=document.getElementById("obj");
if(curindex==array.length-1)
{
curindex=0;
}else{
curindex++;
}
obj.src=array[curindex];
}
setInterval(circulate,timeInterval);//把setInterval放到 定义circulate函数的后面
追问大哥,我试了下,进入以后网页还是没有循环图片,你看下我调用脚本有没有出错好吗?