setTimeout (kode, Millisec) //- Jalankan kode setelah waktu yang ditentukan
Kode harus;
Millisec harus;
clearTimeout (setTimeOutId) //- Batalkan SetTimeout ()
setInterval (kode, millisec);
Kode harus;
Millisec harus;
ClearInterval (intervalid);
Gunakan SetTimeout (kode, Millisec) untuk mencapai efek setInterval, hanya metode panggilan bersarang;
Di bawah ini adalah halaman hitung mundur
Salinan kode adalah sebagai berikut:
<! Doctype html public "-// w3c // dtd xhtml 1.0 transisi // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv = "konten-tipe" content = "text /html; charset = gb2312" />
<title> unt judul dokumen </iteme>
<type skrip = "Teks/JavaScript">
var c = 6;
var t;
fungsi timeDcount ()
{
var time = document.geteLementById ('txt'). value;
if (time> 0) {
document.geteLementById ('txt'). value = c;
C = C-1;
t = setTimeout ("TimeedCount ()", 1000);
}
kalau tidak{
ClearTimeout (T);
}
}
</script>
</head>
<body>
<sorm>
<input type = "tombol" value = "Mulai waktu!"
<input type = "text" id = "txt" value = "6">
</form>
</body>
</html>