SetTimeout SetInterval

setTimeout only one time, so need recursion. So continues running the function one after one

SetInterval continues running, without stoping, and it runs every intervals, without waiting the former stops.

1. SetTimeout   

function showTime()

{

    var today = new Date();

    alert("The time is: " + today.toString());

    setTimeout("showTime()", 5000);

}

 

2. SetInterval

var intervalProcess = setInterval("showTime()", 5000);

function showTime()

{

    var today = new Date();

    alert("The time is: " + today.toString());

}

clearInterval(intervalProcess);

 

原文地址:https://www.cnblogs.com/kevinge/p/1401529.html