在jQuery中的时间间隔中运行函数 [英] Run a function in time interval in jQuery

查看:828
本文介绍了在jQuery中的时间间隔中运行函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用jQuery制作横幅.当页面加载脚本时,将一张一张地显示一组照片.例如,控制器发送了10张照片,而脚本要求10分钟后30分钟内,每张照片将在30秒内显示.

I want to make a banner by using jQuery. When the page loaded script will show a group of photos one by one. For example, the controller sends 10 photos and each photo will be shown in 30 seconds after 10 minutes the script demand another photo from the controller.

问题是:如何使功能在30秒内运行.我需要在没有任何按钮单击或其他任何操作的时间间隔内运行一个函数.

The question is: How can I make a function that runs in 30 sec. I need to run a function in a time interval without any button click or anything else.

推荐答案

主要方法是:

 setInterval(function () {
        console.log('it works' + new Date());
    },30000);

如果以后需要清除间隔:

If you need to clear interval in future:

var myInterval = setInterval(function () {
            console.log('it works' + new Date());
        },30000); 

将来:

clearInterval(myInterval);

这篇关于在jQuery中的时间间隔中运行函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆