我有一个我无法弄清楚的错误,所以我正在寻求帮助。我有一个带有 javascript 的简单幻灯片代码,我知道故障线,但我只是不知道它为什么会崩溃。
这是完整的代码。
var step=1;
var whichimage=1;
function slideit(){
//if browser does not support the image object, exit.
if (!document.images)
return;
document.images.slide.src=eval("image"+step+".src");
whichimage=step;
if (step==1)
{
changepic(step);
step++;
};
else if (step==2){
changepic(step);
step++;
};
else if (step==3) {
changepic(step);
step=1;
};
setTimeout("slideit()",1500);
}
slideit()
function slidelink(){
if (whichimage==1)
window.location="link1.htm"
else if (whichimage==2)
window.location="link2.htm"
else if (whichimage==3)
window.location="link3.htm"
}
function Pic1(){
if (!document.images)
return;
document.slide.src = image1.src;
step=1;
changepic(step);
}
function Pic2(){
if (!document.images)
return;
document.slide.src = image2.src;
step=2;
changepic(step);
}
function Pic3(){
if (!document.images)
return;
document.slide.src = image3.src;
step=3;
changepic(step);
}
function changepic (x){
if (x==1){
document.getElementById("temp1").setAttribute("class", "slideshowminithumb2");
document.getElementById("temp2").setAttribute("class", "slideshowminithumb");
document.getElementById("temp3").setAttribute("class", "slideshowminithumb");
}
if(x==2){
document.getElementById("temp2").setAttribute("class", "slideshowminithumb2");
document.getElementById("temp1").setAttribute("class", "slideshowminithumb");
document.getElementById("temp3").setAttribute("class", "slideshowminithumb");
}
if(x==3){
document.getElementById("temp3").setAttribute("class", "slideshowminithumb2");
document.getElementById("temp1").setAttribute("class", "slideshowminithumb");
document.getElementById("temp2").setAttribute("class", "slideshowminithumb");
}
}
我知道错误发生在这一行:
if (step==1)
{
changepic(step); /** Here! **/
step++;
};
我知道这一点,因为如果我删除该行,幻灯片脚本可以工作,但我需要它工作,以便在步骤 1 时更改类。