Pencere clearTimeout()
örnek 1
myGreating() işlevinin yürütülmesi nasıl engellenir:
const myTimeout = setTimeout(myGreating, 3000);
function myGreating() {
document.getElementById("demo").innerHTML = "Happy Birthday to You !!"
}
function myStopFunction() {
clearTimeout(myTimeout);
}
Aşağıda daha fazla örnek.
Tanım ve Kullanım
Yöntem clearTimeout()
, yöntemle birlikte ayarlanmış bir zamanlayıcıyı temizler
setTimeout()
.
Not
Bir zaman aşımını temizlemek için setTimeout() işlevinden döndürülen kimliği kullanın:
myTimeout = setTimeout(function, milliseconds);
Ardından, clearTimeout() öğesini çağırarak yürütmeyi durdurabilirsiniz:
clearTimeout(myTimeout);
Ayrıca bakınız:
Sözdizimi
clearTimeout(id_of_settimeout)
parametreler
Parameter | Description |
timeout id | Required. The id returned by the setTimeout() method. |
Geri dönüş değeri
YOK |
Daha fazla örnek
Bu örnekte bir zamanlayıcıyı başlatmak için bir "Başlat" düğmesi, bir sayaç için bir giriş alanı ve zamanlayıcıyı durdurmak için bir "Durdur" düğmesi bulunur:
<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>
Tarayıcı Desteği
clearTimeout()
tüm tarayıcılarda desteklenir:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |