what is setTimeOut() function in javascript?

前端 未结 4 1670
粉色の甜心
粉色の甜心 2020-12-19 21:55

Can i ask what the function of setTimeOut method in javascript?As below:

function startTime()
{
var today=new Date();
var h=today.getHours();
var m=today.get         


        
4条回答
  •  一向
    一向 (楼主)
    2020-12-19 22:19

    setTimeOut sets a timer and executes the given code after that timer timed out. So using your code, if startTime is called once, it is repeated every half second.

    Btw. I assume the delay of 500 ms is used te work around small deviations in the clock. You will want to update the value of the element every whole second. To do that, it is better to calculate the time until the next whole second and set that as a delay. This will give you a more accurate clock.

提交回复
热议问题