[英]Is there a better way to repeat a function, rather than using setTimeout
有沒有更好的方法無限次重復一個函數?
而不是使用:
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);
(function(){
var images = ['1.jpg', '2.jpg', '3.jpg', '4.jpg'],
img = document.getElementById('blerg');
setInterval(function(){
img.src = images[0];
images.push(images.shift());
}, 2500)
})();
或while(true) hangTheBrowser();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.