settimeout (รหัส, millisec) //- เรียกใช้รหัสหลังจากเวลาที่กำหนด
รหัสต้อง;
MILLISEC ต้อง;
ClearTimeOut (setTimeOutID) //- ยกเลิก setTimeOut ()
setInterval (รหัส, มิลลิส);
รหัสต้อง;
MILLISEC ต้อง;
ClearInterval (Intervalid);
ใช้ settimeout (รหัสมิลลิส) เพื่อให้ได้เอฟเฟกต์ setInterval, วิธีการโทรซ้อนกันเท่านั้น
ด้านล่างเป็นหน้านับถอยหลัง
การคัดลอกรหัสมีดังนี้:
<! doctype html public "-// w3c // dtd xhtml 1.0 transitional // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv = "content-type" content = "text /html; charset = gb2312" />
<tite> เอกสารชื่อ UNT </title>
<script type = "text/javascript">
var c = 6;
var t;
ฟังก์ชั่น TimedCount ()
-
var time = document.getElementById ('txt') ค่า;
ถ้า (เวลา> 0) {
document.getElementById ('txt'). value = c;
C = C-1;
t = settimeout ("timedCount ()", 1,000);
-
อื่น{
ClearTimeout (t);
-
-
</script>
</head>
<body>
<form>
<อินพุต type = "button" value = "เวลาเริ่มต้น!" onclick = "timedcount ()"
<input type = "text" id = "txt" value = "6">
</form>
</body>
</html>