代码示例:(标识:jsck_win_setinterval_progressbar)
<!DOCTYPE html>
<html>
<style>
#myProgress {
  width: 100%;
  height: 30px;
  position: relative;
  background-color: #ddd;
}

#myBar {
  background-color: #4CAF50;
  width: 10px;
  height: 30px;
  position: absolute;
}
</style>
<body>

<h1>JavaScript 进度条</h1>

<div id="myProgress">
  <div id="myBar"></div>
</div>

<br>
<button onclick="move()">点击我</button> 

<script>
function move() {
  const element = document.getElementById("myBar");   
  let width = 0;
  const id = setInterval(frame, 10);
  function frame() {
    if (width == 100) {
      clearInterval(id);
    } else {
      width++; 
      element.style.width = width + '%'; 
    }
  }
}
</script>

</body>
</html>
运行结果: