Jendela clearInterval () metode
Definisi dan Penggunaan
Metode clearInterval () untuk membatalkan setInterval yang () pengaturan timeout.
Metode parameter clearInterval () harus ID nilai yang dikembalikan oleh setInterval ().
tatabahasa
clearInterval(id_of_setinterval)
Dukungan Browser
Semua browser utama mendukung clearInterval () metode
contoh
contoh
Setiap 1000 milidetik memanggil jam () fungsi. Jam () fungsi untuk memperbarui jam. Contoh ini juga memiliki tombol untuk menghentikan jam:
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "utf-8">
<Title> Tutorial ini (w3big.com) </ title>
</ Kepala>
<Body>
<Input type = "text" id = "Jam" />
<Script type = "text / javascript">
var int = self.setInterval ( "jam ()", 1000);
fungsi jam () {
var d = new Date ();
var t = d.toLocaleTimeString ();
document.getElementById ( "jam") value = t .;
}
</ Script>
<Tombol onclick = "int = window.clearInterval (int)"> Berhenti </ button>
</ Body>
</ Html>
<Html>
<Head>
<Meta charset = "utf-8">
<Title> Tutorial ini (w3big.com) </ title>
</ Kepala>
<Body>
<Input type = "text" id = "Jam" />
<Script type = "text / javascript">
var int = self.setInterval ( "jam ()", 1000);
fungsi jam () {
var d = new Date ();
var t = d.toLocaleTimeString ();
document.getElementById ( "jam") value = t .;
}
</ Script>
<Tombol onclick = "int = window.clearInterval (int)"> Berhenti </ button>
</ Body>
</ Html>
Coba »
objek jendela