'setInterval'vs'setTimeout' [英] 'setInterval' vs 'setTimeout'

查看:145
本文介绍了'setInterval'vs'setTimeout'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

setInterval

setInterval

setTimeout

setTimeout

在JavaScript中?

in JavaScript?

推荐答案

setTimeout(表达式,超时); 运行代码/函数超时后一次。

setTimeout(expression, timeout); runs the code/function once after the timeout.

setInterval(表达式,超时); 以间隔运行代码/函数,它们之间的超时长度。

setInterval(expression, timeout); runs the code/function in intervals, with the length of the timeout between them.

示例:

var intervalID = setInterval(alert, 1000); // Will alert every second.
// clearInterval(intervalID); // Will clear the timer.

setTimeout(alert, 1000); // Will alert once, after a second.

这篇关于'setInterval'vs'setTimeout'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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