gpt4 book ai didi

javascript - 有没有更好的方法来重复一个函数,而不是使用 setTimeout

转载 作者:行者123 更新时间:2023-12-02 19:06:56 24 4
gpt4 key购买 nike

有没有更好的方法来无限次重复一个函数?

而不是使用:

    setTimeout(myfunction(), 10)

我如何将其添加到其中?当我替换 setTimeout 时,顺序变得很奇怪。

    <img id="slideshow" src="4.JPG" alt="cheese" width="264" height="264"/>
<script>
source=["1.jpg", "2.JPG", "3.JPG", "4.JPG"];
var i=0
function show(){
document.getElementById("slideshow").src = source[i];
if (i<source.length - 1)
i++
else
i=0
setTimeout("show()",2500)
}
show()
</script>

最佳答案

您正在寻找window.setInterval(function, 1000);

关于javascript - 有没有更好的方法来重复一个函数,而不是使用 setTimeout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14226791/

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