【发布时间】:2016-04-17 18:56:56
【问题描述】:
我正在制作一个 javascript 幻灯片,但我不确定如何为每个图像添加标题,上一个按钮无法正常工作(两次或多次单击后不显示图像)我也将如何能够转到幻灯片的第一个和最后一个图像?
var index=4;
var titles=[1,2,3,4,5];
// LIST OF CAPTİONS
caption[0] = "Caption for the first image";
caption[1] = "Caption for the second image";
caption[2] = "Caption for the third image";
caption[3] = "Caption for the first image";
caption[4] = "Caption for the second image";
caption[5] = "Caption for the third image";
function NextSlide()
{
if (index >= 5){index=0}
var img = document.getElementById("img1");
var slideName="images/img" + titles[index++] + ".jpg";
img.src=slideName;
}
function PrevSlide()
{
if (index >= 5){index=0}
var img = document.getElementById("img1");
var slideName="images/img" + titles[index--] + ".jpg"; img.src=slideName;
}
function last()
{
index = 1;
}
【问题讨论】:
-
caption定义在哪里? -
当您致电
PrevSlide时,您永远不会检查您是否小于零。
标签: javascript html arrays slideshow