首页 > Web开发 > 详细

JS实现时钟程序

时间:2015-10-08 16:32:19      阅读:264      评论:0      收藏:0      [点我收藏+]
<!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>

截图如下:
技术分享

 

JS实现时钟程序

原文:http://www.cnblogs.com/lesuso/p/4861171.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!