Timer 1
Wird verwendet, um festzustellen, dass ein Programm nach einem bestimmten Zeitraum ausgeführt wird.
setTimeout ():
Format: [Timer -Objektname =] setTimeout ("<xpression>", Millisekunden)
Funktion: Führen Sie einmal <xpression> aus.
Beispiel:
Die Codekopie lautet wie folgt:
<! DocType html>
<html>
<kopf>
<title> Timer1.html </title>
<meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">
<meta http-äquiv = "Beschreibung" content = "Dies ist meine Seite">
<meta http-äquiv = "content-type" content = "text/html; charset = utf-8">
<!-<link rel = "stylesheet" type = "text/css" href = "./ styles.css">->
<script type = "text/javaScript">
Funktion count ()
{
setTimeout ("alert ('Ausführung erfolgreich!'), 7000);
}
</script>
</head>
<body>
<Eingabe type = "button" value = "klicken Sie mich" onclick = "count ();">
</body>
</html>
Timer 2
Ausdrücke wiederholt in einem bestimmten Zeitintervall ausführen.
setInterval ():
Format: [Timer -Objektname =] setInterval ("<xpression>", Millisekunden)
Funktion: Wiederholen Sie den <xpression>, bis das Fenster und das Rahmen geschlossen sind oder klareInterval ausgeführt werden.
ClearInterval ():
Format: ClearInterval (Timer -Objektname)
Funktion: Timer beenden
Beispiel:
Die Codekopie lautet wie folgt:
<! DocType html>
<html>
<kopf>
<title> Timer2.html </title>
<meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">
<meta http-äquiv = "Beschreibung" content = "Dies ist meine Seite">
<meta http-äquiv = "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); // Zeit beginnt beim Laden der Seite
Funktion count ()
{
document.getElementById ("num"). Innerhtml = Sec ++;
}
Funktion stopCount ()
{
ClearInterval (Timer); // Stoppen Sie das Ausführen des Timers
}
</script>
</head>
<body>
<font color = "rot" id = "num"> 0 </font>
<input type = "button" value = "stop" onclick = "stopCount ();">
</body>
</html>
Das obige ist der gesamte Inhalt dieses Artikels. Ich hoffe es gefällt euch