Window clearTimeout() 方法

ການອະທິບາຍແລະການນຳໃຊ້

clearTimeout() ວິທີການການນຳໃຊ້ ພາສາ setTimeout() ທີ່ຖືກກວດສອບ

ການສັນຍາວັດສະດຸ

ສຳລັບການລົບການຖືກກະຕຸ້ນເວລາອີກ ພາສາ setTimeout() ອີງຕາມ id ທີ່ບັນທຶກ

myTimeout = setTimeout(function, milliseconds);

ຫຼັງຈາກນັ້ນທ່ານສາມາດເຂົ້າໃຊ້ clearTimeout() ເພື່ອປິດການດຳເນີນ:}

clearTimeout(myTimeout);

ບໍ່ມີ.

ພາສາ setTimeout()

ພາສາ setInterval()

ພາສາ clearInterval()

ຄວາມນິຍົມ

ບົດຕິດຕາມ 1

ວິທີທີ່ຈະຫຼີກລ່ວງການດຳເນີນ myGreeting():

const myTimeout = setTimeout(myGreeting, 3000);
function myGreeting() {
  document.getElementById("demo").innerHTML = "Happy Birthday to You !!"
}
function myStopFunction() {
  clearTimeout(myTimeout);
}

ທ່ານຈະພະຍາຍາມດັ່ງກ່າວ

ບົດຕິດຕາມ 2

ບົດຕິດຕາມນີ້ມີຄຳມືຂຶ້ນການເລີ່ມການຄັ້ງຄັງ, ບໍລິສັດພິມຂາຍຂາຍຄຳມືການປິດຄັ້ງຄັງ:

<button onclick="startCount()">Start count!</button>
<input type="text" id="demo">
<button onclick="stopCount()">Stop count!</button>
<script>
let counter = 0;
let timeout;
let timer_on = 0;
function timedCount() {
  document.getElementById("demo").value = counter;
  counter++;
  timeout = setTimeout(timedCount, 1000);
}
function startCount() {
  if (!timer_on) {
    timer_on = 1;
    timedCount();
  }
}
function stopCount() {
  clearTimeout(timeout);
  timer_on = 0;
}
</script>

ທ່ານຈະພະຍາຍາມດັ່ງກ່າວ

ສັນຍາວິທະຍາ

clearTimeout(timeoutId)

ພຂາທີ

ພຂາທີ ອະທິບາຍ
timeoutId ສະຖິນຍິງ.ພາສາ setTimeout() ຄຳຕອບຫຼັງທີ່ມາ.

ຄຳຕອບຫຼັງ

ບໍ່ມີ.

ຄວາມຊີ້ວັດ

clearTimeout() ການຍົກເລີກການດຳເນີນບັນນາທິວິທະຍາການຕົກຕັ້ງສະເພາະ,ການເອິ້ນ ພາສາ setTimeout() ສາມາດດຳເນີນບັນນາທິວິທະຍາການນີ້ຫຼັງຈາກຄັ້ງ. ພຂາທີ timeoutId ແມ່ນການເອິ້ນ ພາສາ setTimeout() ກັບຄຳຕອບຫຼັງຈາກນັ້ນ,ມັນຈະສະແດງວ່າຈະຖອນການດຳເນີນບັນນາທິວິທະຍາການທີ່ຈະຖອນການດຳເນີນ (ສາມາດມີຫຼາຍຫຼາຍບັນນາທິວິທະຍາການ).

ການສະໜັບສະໜູນ

所有浏览器都支持 clearTimeout():

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
ການສະໜັບສະໜູນ ການສະໜັບສະໜູນ ການສະໜັບສະໜູນ ການສະໜັບສະໜູນ ການສະໜັບສະໜູນ ການສະໜັບສະໜູນ