setInterval()中的函数无延迟地执行 [英] function in setInterval() executes without delay

查看:156
本文介绍了setInterval()中的函数无延迟地执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个jquery应用程序,通过使用setInterval()在指定的时间间隔后隐藏图像。问题是隐藏图像功能立即执行而没有延迟。

I am in the process of making a jquery application to hide an image after a specified interval of time by using setInterval(). The problem is that the hide image function executes immediately without delay.

$(document).ready(function() {

  setInterval(change(), 99999999);

  function change() {
    $('#slideshow img').eq(0).removeClass('show');

  }

});

我在 jsfiddle

推荐答案

http://jsfiddle.net/wWHux/3/

你立即调用了这个函数而不是将其传递给 setInterval

You called the function immediately instead of passing it to setInterval.

setInterval(change,1500) - 将函数更改更改为 setInterval

setInterval( change, 1500 ) - passes function change to setInterval

setInterval(change(),1500) - 调用函数更改并传递结果( undefined )到 setInterval

setInterval( change(), 1500 ) - calls the function change and passes the result (undefined) to setInterval

这篇关于setInterval()中的函数无延迟地执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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