Loop timer in JavaScript

前端 未结 6 941

I need to execute a piece of JavaScript code say, each 2000 milliseconds.

setTimeout(\'moveItem()\',2000)

The above will execute a function

6条回答
  •  没有蜡笔的小新
    2020-11-28 21:31

    You should try something like this:

     function update(){
        i++;
        document.getElementById('tekst').innerHTML = i;
        setInterval(update(),1000);
        }
    

    This means that you have to create a function in which you do the stuff you need to do, and make sure it will call itself with an interval you like. In your body onload call the function for the first time like this:

    
    

提交回复
热议问题