JavaScript中的幻灯片放映问题

时间:2015-12-08 02:06:09

标签: javascript jquery

我远离计算机程序员,但我的javascript代码显然有问题,因为我的幻灯片显示无法正常工作。我已经尝试过我所知道的一切,但我还不知道如何调试代码。你能帮忙吗?

var showCounter = 0
var theTimeout
function myShow() {
    if (showCounter == 0) {
        document.internship.src = "withwoodendolphins.jpg"
        showCounter = 1
    } else if (showCounter == 1) {
        document.internship.src = "mewithalligator.jpg"
        showCounter = 2
    } else if (showCounter == 2) {
        document.internship.src = "mewithsealion.jpg"
        showCounter = 3
    } else if (showCounter == 3) {
        document.internship.src = "mewithterrapin.jpg"
        showCounter = 4
    } else if (showCounter == 4) {
        document.internship.src = "paperwork.jpg"
        showCounter = 5
    } else if (showCounter == 5) {
        document.internship.src = "sealion.jpg"
        showCounter = 6
    } else if (showCounter == 6) {
        document.internship.src = "seastar.jpg"
        showCounter = 7
    } else if (showCounter == 7) {
        document.internship.src = "snaileggs.jpg"
        showCounter = 8
    } else if (showCounter == 8) {
        document.internship.src = "cj.jpg"
        showCounter = 9
    } else if (showCounter == 9) {
        document.internship.src = "turtle1.jpg"
        showCounter = 10
    } else if (showCounter == 10) {
        document.internship.src = "waterspout.jpg"
        showCounter = 11
    } else if (showCounter == 11) {
        document.internship.src = "camera.jpg"
        showCounter = 12
    } else if (showCounter == 12) {
        document.internship.src = "camera2.jpg"
        showCounter = 13
    } else if (showCounter == 13) {
        document.internship.src = "clouds.jpg"
        showCounter = 14
    } else if (showCounter == 14) {
        document.internship.src = "clouds1.jpg"
        showCounter = 15
    } else if (showCounter == 15) {
        document.internship.src = "dolphin2.jpg"
        showCounter = 16
    } else if (showCounter == 16) {
        document.internship.src = "dolphin3.jpg"
        showCounter = 17
    } else if (showCounter == 17) {
        document.internship.src = "dolphin6.jpg"
        showCounter = 18
    } else if (showCounter == 18) {
        document.internship.src = "dolphin7.jpg"
        showCounter = 19
    } else if (showCounter == 19) {
        document.internship.src = "dolphin8.jpg"
        showCounter = 20
    } else if (showCounter == 20) {
        document.internship.src = "dolphin10.jpg"
        showCounter = 21
    } else if (showCounter == 21) {
        document.internship.src = "dominos.jpg"
        showCounter = 22
    } else if (showCounter == 22) {
        document.internship.src = "interns1.jpg"
        showCounter = 23
    } else if (showCounter == 23) {
        document.internship.src = "ontheboat1.jpg"
        showCounter = 24
    } else if (showCounter == 24) {
        document.internship.src = "immsdolphin.jpg"
        showCounter = 25
    } else {
        document.internship.src = "dolphin4.jpg"
        showCounter = 0
    }

    theTimeout = setTimeout("myShow ()", 2000)
}

var pictureCounter = 0
var myTimeout

function pictureShow() {
    if (pictureCounter == 0) {
        document.dolphins.src = "dolphin11.jpg"
        pictureCounter = 1
    } else if (pictureCounter == 1) {
        document.dolphins.src = "dolphin12.jpg"
        pictureCounter = 2
    } else if (pictureCounter == 2) {
        document.dolphins.src = "dolphin1.jpg"
        pictureCounter = 3
    } else if (pictureCounter == 3) {
        document.dolphins.src = "dolphin5.jpg"
        pictureCounter = 4
    } else if (pictureCounter == 4) {
        document.dolphins.src = "interns.jpg"
        pictureCounter = 5
    } else if (pictureCounter == 5) {
        document.dolphins.src = "mewithdolphin.jpeg"
        pictureCounter = 6
    } else if (pictureCounter == 6) {
        document.dolphins.src = "mewithneworleans.jpg"
        pictureCounter = 7
    } else if (pictureCounter == 7) {
        document.dolphins.src = "ocean.jpg"
        pictureCounter = 8
    } else if (pictureCounter == 8) {
        document.dolphins.src = "ontheboat.jpg"
        pictureCounter = 9
    } else if (pictureCounter == 9) {
        document.dolphins.src = "sealion1.jpg"
        pictureCounter = 10
    } else if (pictureCounter == 10) {
        document.dolphins.src = "seastar1.jpg"
        pictureCounter = 11
    } else if (pictureCounter == 11) {
        document.dolphins.src = "sunset.jpg"
        pictureCounter = 12
    } else if (pictureCounter == 12) {
        document.dolphins.src = "terrapin1.jpg"
        pictureCounter = 13
    } else if (pictureCounter == 13) {
        document.dolphins.src = "terrapinxray.jpg"
        pictureCounter = 14
    } else if (pictureCounter == 14) {
        document.dolphins.src = "apollojumping.jpg"
        pictureCounter = 15
    } else if (pictureCounter == 15) {
        document.dolphins.src = "internswithboat.jpg"
        pictureCounter = 16
    } else if (pictureCounter == 16) {
        document.dolphins.src = "fish.jpg"
        pictureCounter = 17
    } else if (pictureCounter == 17) {
        document.dolphins.src = "fish2.jpg"
        pictureCounter = 18
    } else if (pictureCounter == 18) {
        document.dolphins.src = "apollobasketball.jpg"
        pictureCounter = 19
    } else if (pictureCounter == 19) {
        document.dolphins.src = "sloth.jpg"
        pictureCounter = 20
    } else {
        document.dolphins.src = "meandsealions1.jpg"
        pictureCounter = 0
    }

    myTimeout = setTimeout("pictureShow ( )", 2000)
}

1 个答案:

答案 0 :(得分:0)

setTimeout接收function,而不是字符串。您需要将函数直接传递给setTimeout:

myTimeout = setTimeout(pictureShow, 2000)

此外,你真的不应该像这样编写幻灯片。尝试类似:

var images = ["withwoodendolphins.jpg", "mewithalligator.jpg", ...];

function myShow() {
    document.dolphins.src = images[showCounter];
    showCounter++;
    if (showCounter >= 25)
        showCounter = 25;
}