Window clearTimeout()
ဥပမာ ၁
myGreating() ကို execute လုပ်နည်း-
const myTimeout = setTimeout(myGreating, 3000);
function myGreating() {
document.getElementById("demo").innerHTML = "Happy Birthday to You !!"
}
function myStopFunction() {
clearTimeout(myTimeout);
}
အောက်တွင် နောက်ထပ် ဥပမာများ။
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
method သည် method clearTimeout()
နှင့်အတူ timer set ကိုရှင်းလင်းသည်
setTimeout()
။
မှတ်ချက်
အချိန်ကုန်သွားခြင်းကို ရှင်းလင်းရန် setTimeout() မှ ပြန် ပေးသော id ကို အသုံးပြုပါ။
myTimeout = setTimeout(function, milliseconds);
ထို့နောက် clearTimeout():
clearTimeout(myTimeout);
ကိုလည်းကြည့်ပါ-
အထားအသို
clearTimeout(id_of_settimeout)
ကန့်သတ်ချက်များ
Parameter | Description |
timeout id | Required. The id returned by the setTimeout() method. |
တန်ဖိုးကို ပြန်ပေးသည်။
မရှိပါ။ |
နောက်ထပ် ဥပမာများ
ဤဥပမာတွင် အချိန်တိုင်းကိရိယာတစ်ခုစတင်ရန် "Start" ခလုတ်၊ ကောင်တာတစ်ခုအတွက် ထည့်သွင်းမှုအကွက်နှင့် အချိန်တိုင်းကိရိယာကိုရပ်တန့်ရန် "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>
Browser ပံ့ပိုးမှု
clearTimeout()
ဘရောက်ဆာအားလုံးတွင် ထောက်ခံသည်-
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |