setTimeout和setInterval的区别

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

<html>
<head>
<script>
var i = 0;
function sett()
{
    document.body.innerHTML=i++;
    setTimeout("sett()",500);
}
setTimeout("sett()",500);
</script> 
</head>
<body>
</html>

setInterval()从载入后,每隔指定的时间就执行一次表达式:

<html>
<head>
<script>
var i = 0;
function sett()
{
    document.body.innerHTML=i++;
}
setInterval("sett();", 500);
</script> 
</head>
<body>
</body>
</html>
</body>
</html>
原文地址:https://www.cnblogs.com/eastson/p/2796298.html