Timer 1
Digunakan untuk menentukan bahwa suatu program dieksekusi setelah periode waktu tertentu.
setTimeout ():
Format: [Timer Name Objek =] setTimeout ("<presi>", milidetik)
Fungsi: Jalankan <pekspresi> sekali.
contoh:
Salinan kode adalah sebagai berikut:
<! Doctype html>
<Html>
<head>
<title> timer1.html </iteme>
<meta http-equiv = "kata kunci" content = "kata kunci1, kata kunci2, kata kunci3">
<meta http-equiv = "description" content = "This is my Page">
<meta http-equiv = "konten tipe" content = "text/html; charset = utf-8">
<!-<tautan rel = "stylesheet" type = "text/css" href = "./ styles.css">->
<type skrip = "Teks/JavaScript">
function count ()
{
setTimeout ("alert ('eksekusi berhasil!')", 7000);
}
</script>
</head>
<body>
<input type = "tombol" value = "klik saya" onclick = "count ();">
</body>
</html>
Timer 2
Jalankan ekspresi berulang kali pada interval waktu tertentu.
setInterval ():
Format: [Timer Name Obyek =] SetInterval ("<pekspresi>", milidetik)
Fungsi: Ulangi <presi> sampai jendela dan bingkai ditutup atau jelas dieksekusi.
clearInterval ():
Format: ClearInterval (nama objek timer)
Fungsi: Menghentikan pengatur waktu
contoh:
Salinan kode adalah sebagai berikut:
<! Doctype html>
<Html>
<head>
<title> timer2.html </iteme>
<meta http-equiv = "kata kunci" content = "kata kunci1, kata kunci2, kata kunci3">
<meta http-equiv = "description" content = "This is my Page">
<meta http-equiv = "konten tipe" content = "text/html; charset = utf-8">
<!-<tautan rel = "stylesheet" type = "text/css" href = "./ styles.css">->
<type skrip = "Teks/JavaScript">
var sec = 0;
var timer = setInterval ("count ();", 1000); // Waktu dimulai saat halaman memuat
function count ()
{
document.geteLementById ("num"). innerHtml = sec ++;
}
fungsi stopcount ()
{
ClearInterval (timer); // Hentikan menjalankan timer
}
</script>
</head>
<body>
<font color = "red" id = "num"> 0 </font>
<input type = "tombol" value = "stop" onclick = "stopcount ();">
</body>
</html>
Di atas adalah seluruh konten artikel ini. Saya harap Anda menyukainya