Venster clearTimeout()
Voorbeeld 1
Hoe om te verhoed dat myGreating() uitgevoer word:
const myTimeout = setTimeout(myGreating, 3000);
function myGreating() {
document.getElementById("demo").innerHTML = "Happy Birthday to You !!"
}
function myStopFunction() {
clearTimeout(myTimeout);
}
Meer voorbeelde hieronder.
Definisie en gebruik
Die clearTimeout()
metode maak 'n timer wat met die
setTimeout()
metode gestel is skoon.
Let wel
Om 'n uitteltyd uit te vee, gebruik die ID wat van setTimeout():
myTimeout = setTimeout(function, milliseconds);
Dan kan jy die uitvoering stop deur clearTimeout ():
clearTimeout(myTimeout);
Sien ook:
Sintaksis
clearTimeout(id_of_settimeout)
Grense
Parameter | Description |
timeout id | Required. The id returned by the setTimeout() method. |
Terugkeerwaarde
GEEN |
Meer voorbeelde
Hierdie voorbeeld het 'n "Begin"-knoppie om 'n tydteller te begin, 'n invoerveld vir 'n teller, en 'n "Stop"-knoppie om die tydteller te stop:
<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>
Blaaierondersteuning
clearTimeout()
word in alle blaaiers ondersteun:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |