我正在尝试使用java脚本创建图像幻灯片。这是我的代码
<script type="text/javascript">
//variable that will increment through the images
var step = 1
function slideit() {
var image1 = ["imges/IMG_0579.JPG","imges/IMG_0580.JPG","imges/IMG_0581.JPG"];
//var image2 = new Image()
// var image3 = new Image()
//if browser does not support the image object, exit.
document.write("hello");
document.getElementById("slide").src = image1[step];
document.write("kjds");
if (step < 3)
step++;
else
step = 1;
//call function "slideit()" every 2.5 seconds
setTimeout("slideit()", 2500);
}
slideit();
//-->
</script>
我收到控制台错误src不为空
这里是img元素
<img id="slide" src="imges/IMG_0588.JPG" />
答案 0 :(得分:0)
<html>
<head>
<title>test</title>
</head>
<body>
<img id="slide" src="#" />
</body>
<script type="text/javascript">
var step = 1
function slideit() {
var image1 = ["imges/IMG_0579.JPG","imges/IMG_0580.JPG","imges/IMG_0581.JPG"];
document.getElementById("slide").src = image1[step];
if (step < 3)
step++;
else
step = 1;
//call function "slideit()" every 2.5 seconds
setTimeout("slideit()", 2500);
}
slideit();
</script>
</html>