Complete javascript timer instance, javascript Timer
This article describes the complete implementation of the javascript timer. Share it with you for your reference. The specific implementation method is as follows:
Copy codeThe Code is as follows: <! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Title> timer </title>
<Script type = "text/javascript">
Var timer = null;
Function begin (){
Var date = new Date ();
Var current_time = date. getFullYear () + '-' + date. getMonth () + '-' + date. getDate () + '';
Current_time + = date. getHours () + ':' + date. getMinutes () + ':' + date. getSeconds ();
Document. getElementById ('current _ Time'). value = current_time;
Timer = setTimeout ('in in () ', 1000 );
}
Function end (){
ClearTimeout (timer); // clears the timer object
}
</Script>
</Head>
<Body>
<Input type = "text" name = "current_time" id = "current_time"/> <input type = "button" value = "start" onclick = "begin ();">
<Input type = "button" value = "end" onclick = "end ();"/> <br/>
</Body>
</Html>
I hope this article will help you design javascript programs.