Javascript希望有一个标签,您可以检查该标签以自动刷新页面

我尝试制作一个标签,当您“检查”它时,它将每5秒自动刷新一次页面。我找到了几个线程,但没有起作用!到目前为止,这是我做的事情:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <label>
      <input
        type="checkbox"
        name="refresh"
        autocomplete="off"
        value="autorefreshoff"
        id="refresh-btn"
        onclick="refresh()"
      />
    </label>
  </body>
  <script>
    //Don't know what do do here, tried this:
    function refresh() {
      window.location.reload(1);
    }
  </script>
</html>

我猜想我必须在我的JavaScript代码中做一个延迟循环吗?因此,每当“选中”此标签时,它就会每5秒钟遍历javascript代码一次;如果我要关闭标签,它将停止循环。

不幸的是,您不太了解javascript。