Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
540 views
in Technique[技术] by (71.8m points)

javascript - 在jQuery中每5秒调用一次函数的最简单方法是什么? [重复](What's the easiest way to call a function every 5 seconds in jQuery? [duplicate])

This question already has an answer here:(这个问题已经在这里有了答案:)

Calling a function every 60 seconds 11 answers(每60秒调用一次函数 11个答案)

JQuery, how to call a function every 5 seconds.(jQuery,如何每5秒调用一次函数。)

I'm looking for a way to automate the changing of images in a slideshow.(我正在寻找一种自动化幻灯片显示中图像更改的方法。) I'd rather not install any other 3rd party plugins if possible.(如果可能的话,我宁愿不安装其他任何第三方插件。)   ask by ensnare translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You don't need jquery for this, in plain javascript, the following will work!(您不需要为此使用纯JavaScript的jquery,以下方法将起作用!)

window.setInterval(function(){ /// call your function here }, 5000); To stop the loop you can use(要停止循环,您可以使用) clearInterval()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...