为什么setTimeout立即执行? [英] Why is setTimeout executing immediately?

查看:534
本文介绍了为什么setTimeout立即执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的JavaScript setTimeout 函数,但它拒绝工作

  setTimeout(timeup(tc,selected),10000)

...这是函数:

  timeup = function(clt,clo)
{
alert(time up )
}

...并且时间提醒将立即显示,而不是10秒有人可以告诉我为什么发生这种情况吗?

解决方案

因为您实际上正在调用 timeup (tc,selected)函数在setTimeout函数内。

try:

 setTimeout(function(){
timeup(tc,selected);
},10000);


I have a simple JavaScript setTimeout function, but it is refusing to work

setTimeout(timeup(tc,chosen),10000)

... and this is the function:

timeup = function (clt,clo)
{   
    alert("time up")
}

... and the time up alert shows up immediately instead of after 10 seconds can someone tell me why this is happening please?

解决方案

because you're actually calling the timeup(tc,chosen) function inside the setTimeout function.

try:

setTimeout(function(){
  timeup(tc,chosen);
}, 10000);  

这篇关于为什么setTimeout立即执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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