Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript函数调用不循环图像数组_Javascript_Image Gallery_Function Call - Fatal编程技术网

javascript函数调用不循环图像数组

javascript函数调用不循环图像数组,javascript,image-gallery,function-call,Javascript,Image Gallery,Function Call,创建了这个简单的图像阵列库 javascript函数调用不循环图像数组 var imagecount=0; var imageArray = ["images/1.jpg","images/2.jpg","images/3.jpg","images/4.jpg"]; var allimages=imageArray.length-1; function next() { imagecount++; if(imagecount>allimages) { ima

创建了这个简单的图像阵列库

javascript函数调用不循环图像数组

var imagecount=0;
var imageArray = ["images/1.jpg","images/2.jpg","images/3.jpg","images/4.jpg"];
var allimages=imageArray.length-1;


function next()
{
    imagecount++;
    if(imagecount>allimages) {
      imagecount=0;
    }
    document.getElementById("slideshow").src=imageArray[imagecount];
}

function prev()
{
    imagecount--;
    if(imagecount<0) {
      imagecount=allimages;
    }
    document.getElementById("slideshow").src=imageArray[imagecount];
}

document.getElementById("next").onclick=next;

document.getElementById("previous").onclick=prev;
var-imagecount=0;
var imageArray=[“images/1.jpg”、“images/2.jpg”、“images/3.jpg”、“images/4.jpg”];
var allimages=imageArray.length-1;
函数next()
{
imagecount++;
如果(图像计数>大图像){
imagecount=0;
}
document.getElementById(“slideshow”).src=imageArray[imagecount];
}
函数prev()
{
图像计数--;

如果(imagecount您很可能超出数组边界。更改:

if(imagecount>allimages){

看看这个,这正是你的代码,对我来说很有用


这可能是
浏览器
的一个特定问题。

您是否有任何错误?您是否正在调试以查看它停止的位置?假设
#slideshow
是一个
img
标记,您在这里编写的代码应该可以工作。是的,它是一个图像标记。感谢它的工作,我在声明变量和声明函数之间还有两个其他函数有错误。感谢帮助在ans中发布代码而不是将其链接到fiddle始终是一种好的做法。我知道,但是没有从他的原始文件中更改代码。但是感谢编辑:)谢谢,在变量和函数之间的代码中安装了错误。
if(imagecount>allimages-1){