原文地址:

[setTimeout]
setTimeout(表达式,延时时间)
在执行时,是在载入后延迟指定时间后,去执行一次表达式,记住,次数是一次

用setTimeout实现的自动变化显示随机数的效果:

<html>
<head>
<script>
window.onload
=sett;
function sett()
{
document.body.innerHTML
=Math.random();
setTimeout(
sett(),500);
}
</script>
</head>
<body>
</body>
</html>


[setInterval]
setInterval(表达式,交互时间)
则不一样,它从载入后,每隔指定的时间就执行一次表达式

用setInterval实现的自动变化显示随机数的效果:

<html>
<head>
<script>
function sett()
{
document.body.innerHTML
=Math.random();
}
setInterval(
sett(), 500);
</script>
</script>
</head>
<body>
</body>
</html>

  

相关文章:

  • 2021-08-08
  • 2021-10-13
  • 2021-09-13
  • 2022-12-23
  • 2021-06-17
  • 2021-11-19
  • 2021-04-21
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-10
  • 2021-08-09
  • 2022-12-23
  • 2021-07-01
相关资源
相似解决方案