This article illustrates the full implementation method of JavaScript timer. Share to everyone for your reference. The implementation methods are as follows:
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<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 (' Begin () ', 1000);
}
Function End () {
Cleartimeout (timer); Clear off Timer objects
}
</script>
<body>
<input type= "text" name= "Current_time" id= "Current_time"/><input "button" type= "Start" value= "Begin ();" >
<input type= "button" value= "ends" onclick= "End" (); " /><br/>
</body>
I hope this article will help you with your JavaScript programming.