[英]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.