标签:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JS实现时钟程序</title> <script> //获取对象 function $(id) { return document.getElementById(id); } //定时器 var timer; //获取时间 function display() { var date = new Date(); var str = date.getHours()+‘-‘+date.getMinutes()+‘-‘+date.getSeconds(); $(‘result‘).value = str; timer = setTimeout(‘display()‘,1000); } window.onload = function() { $(‘begin‘).onclick = display; $(‘stop‘).onclick = function() { clearTimeout(timer); } } </script> </head> <body> <input type=‘text‘ id=‘result‘/> <hr /> <input type=‘button‘ id=‘begin‘ value=‘Start‘/> <input type=‘button‘ id=‘stop‘ value=‘Stop‘ /> </body> </html>
截图如下:
标签:
原文地址:http://www.cnblogs.com/lesuso/p/4861171.html