مؤقت 1
تستخدم لتحديد أن البرنامج يتم تنفيذه بعد فترة زمنية محددة.
setTimeout ():
التنسيق: [اسم كائن المؤقت =]
الوظيفة: تنفيذ <spression> مرة واحدة.
مثال:
نسخة الكود كما يلي:
<! doctype html>
<html>
<head>
<title> timer1.html </title>
<meta http-equiv = "الكلمات الرئيسية" content = "Keyword1 ، Keyword2 ، Keyword3">
<meta http-equiv = "description" content = "This is is my past">
<meta http-equiv = "content-type" content = "text/html ؛ charset = utf-8">
<!-<link rel = "stylesheet" type = "text/css" href = "./ Styles.css">->
<script type = "text/javaScript">
عدد الوظائف ()
{
setTimeout ("Alert ('Execution Success!)" ، 7000) ؛
}
</script>
</head>
<body>
<type type = "button" value = "Click Me" onClick = "count () ؛">
</body>
</html>
مؤقت 2
تنفيذ التعبيرات مرارًا وتكرارًا في فترة زمنية معينة.
setInterval ():
التنسيق: [اسم كائن Timer =] SetInterval ("<spression>" ، ميلي ثانية)
الوظيفة: كرر <spression> حتى يتم إغلاق النافذة والإطار أو تنفيذ Clearinterval.
ClearInterval ():
التنسيق: ClearInterval (اسم كائن المؤقت)
الوظيفة: إنهاء المؤقت
مثال:
نسخة الكود كما يلي:
<! doctype html>
<html>
<head>
<title> timer2.html </itlem>
<meta http-equiv = "الكلمات الرئيسية" content = "Keyword1 ، Keyword2 ، Keyword3">
<meta http-equiv = "description" content = "This is is my past">
<meta http-equiv = "content-type" content = "text/html ؛ charset = utf-8">
<!-<link rel = "stylesheet" type = "text/css" href = "./ Styles.css">->
<script type = "text/javaScript">
var sec = 0 ؛
var timer = setInterval ("count () ؛" ، 1000) ؛ // يبدأ الوقت عند تحميل الصفحة
عدد الوظائف ()
{
document.getElementById ("num"). innerhtml = sec ++ ؛
}
وظيفة stopcount ()
{
ClearInterval (مؤقت) ؛ // توقف عن تشغيل المؤقت
}
</script>
</head>
<body>
<font color = "red" id = "num"> 0 </font>
<type type = "button" value = "stop" onClick = "stopCount () ؛">
</body>
</html>
ما سبق هو المحتوى الكامل لهذه المقالة. أتمنى أن تعجبك