📜  setinterval on and off - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:10.995000             🧑  作者: Mango

代码示例3
//setinterval on and off

h1 = document.querySelector("h1")
h2 = 0
document.querySelector("#onoff").value = "On"

function funi(){
  tr = setInterval(() =>h1.innerHTML = h2 ++, 1000)
  }

function onoff(){
  currentvalue = document.getElementById('onoff').value;
  if(currentvalue == "Off"){
  clearInterval(tr)
  document.getElementById("onoff").value="On";
  }else{
    funi()
    document.getElementById("onoff").value="Off";
  }
}