每秒调用javascript函数

Kev*_*ans 1 javascript function

我正在尝试学习javascript,现在购买当我尝试重复一个功能时,它似乎无法正常工作.

这是我的功能:

    function heyhey(el){
    el.style.position = "absolute";
    el.style.top = Math.floor(Math.random()*document.body.clientHeight);
    el.style.left = Math.floor(Math.random()*document.body.clientWidth);
  }
  heyhey(document.getElementById('random'));
  //random is the id of my html div
Run Code Online (Sandbox Code Playgroud)

这有效,但我希望每秒调用一次这个函数

我试图重复这个功能:

    function heyhey(el){
            el.style.position = "absolute";
            el.style.top = Math.floor(Math.random()*document.body.clientHeight);
            el.style.left = Math.floor(Math.random()*document.body.clientWidth);
            heyhey();
}
          heyhey(document.getElementById('random'));
Run Code Online (Sandbox Code Playgroud)

我也试过这个:

function heyhey(el){
                el.style.position = "absolute";
                el.style.top = Math.floor(Math.random()*document.body.clientHeight);
                el.style.left = Math.floor(Math.random()*document.body.clientWidth);
                setTimeout(heyhey, 5000);
    }
              heyhey(document.getElementById('random'));
              heyhey();
Run Code Online (Sandbox Code Playgroud)

Que*_*tin 5

function heyhey(el)
Run Code Online (Sandbox Code Playgroud)

该函数需要一个参数

setTimeout(heyhey, 5000);
Run Code Online (Sandbox Code Playgroud)

你没有传递任何东西.将参数指定为第三个及以后的参数setTimeout.

setTimeout(heyhey, 5000, el);
Run Code Online (Sandbox Code Playgroud)