<!DOCTYPE HTML><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title> Auto Growth Timer</title><Scripttype= "Text/javascript"> varAtime; functionclock () {var Time=NewDate (); Atime=time.gethours ()+":"+time.getminutes ()+":"+time.getseconds (); document.getElementById ("Clock"). Value=Atime; } setinterval (Clock, +); </Script></Head><Body><form><inputtype= "text"ID= "Clock"size= " the"style= "background: #000; color: #00ff00; width:55px"; /></form></Body></HTML>
Effect:
Show current time, auto grow
Add a timer for the button (for start and pause)
<!DOCTYPE HTML><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Timer</title><Scripttype= "Text/javascript"> varNum=0; vari; functionStartcount () {document.getElementById ('Count'). Value=num; Num=Num+1; I=SetTimeout ("Startcount ()", +); } functionStopcount () {cleartimeout (i); }</Script></Head><Body> <form> <inputtype= "text"ID= "Count" /> <inputtype= "button"value= "Start"onclick= "Startcount ()"/> <inputtype= "button"value= "Stop"onclick= "Stopcount ()" /> </form></Body></HTML>
Effect:
Click the Start button, counting from 0, one second plus 1. Click the button to stop and keep the current status.
Summarize:
1, SetInterval (Code, interaction time);
Parameter: Code: can be a function name or code string; interaction time: Setting the interaction time
Clearinterval (Id_from_setinterval);
Parameter: The ID value returned by SetInterval ().
2, SetTimeout (code, delay time);
Parameter: Code: can be a function name or code string; delay time: Set delay time
Cleartimeout (id_from_settimeout);
Parameter: The ID value returned by settimeout ().
BOM Learning-javascript Timer Summary