当前位置:
首页 >
前端技术
> javascript
>内容正文
javascript
javascript setTimeout 和 setInterval 区别
生活随笔
收集整理的这篇文章主要介绍了
javascript setTimeout 和 setInterval 区别
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
[setTimeout]
setTimeout(表达式,延时时间)
在执行时,是在载入后延迟指定时间后,去执行一次表达式,记住,次数 是一次
用setTimeout实现的自动变化显示随机数的效果:
<html>
<head>
<script>
window.οnlοad=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>
setTimeout(表达式,延时时间)
在执行时,是在载入后延迟指定时间后,去执行一次表达式,记住,次数 是一次
用setTimeout实现的自动变化显示随机数的效果:
<html>
<head>
<script>
window.οnlοad=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>
摘自: http://www.cnblogs.com/ruxuan/archive/2006/07/04/442490.html
转载于:https://www.cnblogs.com/haoliansheng/archive/2010/12/03/1895278.html
创作挑战赛新人创作奖励来咯,坚持创作打卡瓜分现金大奖总结
以上是生活随笔为你收集整理的javascript setTimeout 和 setInterval 区别的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: [转]用g++编译动态链接库
- 下一篇: JS---捕捉URL地址,以及模仿GET