gpt4 book ai didi

javascript - ReferenceError SetInterval 未定义

转载 作者:行者123 更新时间:2023-11-30 07:39:47 26 4
gpt4 key购买 nike

<分区>

我在 StackOverflow 上看到的几乎所有 SetInterval 错误都是由于将函数名称作为“字符串”传递造成的,但也许我仍然遗漏了某种变量范围问题。请指教!

我正在创建具有暂停和播放功能的幻灯片。播放时,我希望幻灯片每 3 秒前进一次。但是启动 NextSlide 函数的 SetInterval 执行一次后就失败了。

我已经试过了……

SetInterval("nextSlide()", 3000)
SetInterval(nextSlide(), 3000)
var t = SetInterval(nextSlide(), 3000)
var t = SetInterval(function(){nextSlide(), 3000)

...每次都失败。我在这里缺少什么?

var slide_1 = "slide_1";
var slide_2 = "slide_2";
var slideNum = 0;
var odd = true;
var totalMax = 6;
var busy = false;

var allSlides = new Array();
allSlides[0] = "test_01";
allSlides[1] = "test_02";
allSlides[2] = "test_03";
allSlides[3] = "test_04";
allSlides[4] = "test_05";
allSlides[5] = "test_06";
allSlides[6] = "test_07";

function PlaySlide(){
var t = SetInterval(nextSlide(),3000)
document.getElementById("play").style.visibility = "hidden";
document.getElementById("pause").style.visibility = "visible";
}

function nextSlide(){
if(slideNum < totalMax && !busy){
busy = true
document.getElementById("loading").style.zIndex = 4;
slideNum = slideNum + 1
var slide = allSlides[slideNum]
var link = "https://dl.dropboxusercontent.com/u/..." + slide + ".jpg"
odd = !odd
if(odd){document.getElementById(slide_1).src = link} //which <img>.onLoad lauches a fadeIn()
else{document.getElementById(slide_2).src = link}
}
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com