Javascript Photogallery上一个按钮功能不正常

Javascript Photogallery上一个按钮功能不正常,javascript,photo-gallery,Javascript,Photo Gallery,我正在学习javascript,并试图制作一个非常简单的照片库。我的“下一步”按钮的工作原理类似于一次推进一张照片,但当你点击“上一步”按钮时,它会一直返回到第一张图像,而不是仅仅返回一张图像,我不太明白为什么。非常感谢你的帮助 它在这里的jsbin中: 我的代码是: Html: JS: var prev=document.getElementById(“prev”); var next=document.getElementById(“next”); var imge=document.g

我正在学习javascript,并试图制作一个非常简单的照片库。我的“下一步”按钮的工作原理类似于一次推进一张照片,但当你点击“上一步”按钮时,它会一直返回到第一张图像,而不是仅仅返回一张图像,我不太明白为什么。非常感谢你的帮助

它在这里的jsbin中:

我的代码是:

Html:


JS:

var prev=document.getElementById(“prev”);
var next=document.getElementById(“next”);
var imge=document.getElementById(“img”);
var page=document.getElementById(“pg”);
变量imag=[
"http://images.nationalgeographic.com/wpf/media-live/photos/000/667/cache/red-fox-manitoba_66703_990x742.jpg",
"http://images.nationalgeographic.com/wpf/media-live/photos/000/667/cache/martial-arts-india_66701_990x742.jpg?01AD=3Ha8VZ6-_SYLZHH6QOAAPO6CXS3YLIP8x8QYWOGUAWBDSUQ9PY9LJW&01RI=20FA22155E4E381&01NA=na“,
"http://images.nationalgeographic.com/wpf/media-live/photos/000/666/cache/egret-reflection-florida_66697_990x742.jpg",
"http://images.nationalgeographic.com/wpf/media-live/photos/000/667/cache/tornado-storm-saskatchewan_66707_990x742.jpg",
"http://images.nationalgeographic.com/wpf/media-live/photos/000/667/cache/penguin-south-georgia-island_66702_990x742.jpg",
"http://images.nationalgeographic.com/wpf/media-live/photos/000/667/cache/sunset-south-africa_66706_990x742.jpg",
"http://images.nationalgeographic.com/wpf/media-live/photos/000/667/cache/man-motorbike-india_66710_990x742.jpg"
];
var i=0;
setAttribute(“src”,imag[i]);
prev.innerHTML=“prev”;
page.innerHTML=i;
函数next_img(){
i++;
page.innerHTML=i;
setAttribute(“src”,imag[i]);
如果(i==imag.length-1){
next.innerHTML=“下一步”;
prev.innerHTML=“”;
}否则{
next.innerHTML=“”;
prev.innerHTML=“”;
}
返回false;
}
函数prev_img(){
我--;
page.innerHTML=i;
setAttribute(“src”,imag[i]);
如果(i==0){
prev.innerHTML=“prev”;
next.innerHTML=“”;
}否则{
prev.innerHTML=“”;
next.innerHTML=“”;
}
返回false;
}        
在prev\u img()函数中更改

image.setAttribute("src",imag[i]);

在prev_img()函数中

image.setAttribute("src",imag[i]);


grrrr,我希望这不是那种愚蠢的事情。你的眼睛比我好。谢谢你的帮助,在stack允许的情况下,我会在几分钟内接受答案。grrrr,我希望这不是那种愚蠢的事情。你的眼睛比我好。谢谢你的帮助,在stack允许的情况下,我会在几分钟内接受答案。
image.setAttribute("src",imag[i]);
imge.setAttribute("src",imag[i]);