时钟操作js---显示时间点

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body onload="startTime()">
    <div id="timetxt"></div>
    <script>
        function startTime(){
            var today = new Date();
            var h = today.getHours();
            var m = today.getMinutes();
            var s = today.getSeconds();
            m = checkTime(m);
            s = checkTime(s);
            document.getElementById("timetxt").innerHTML = h + ":" + m + ":" + s;
            t = setTimeout(function(){
                startTime();
            },1000); 
        }
        function checkTime(i){
            if(i<10){
                i = "0"+i;
            }
            return i;
        }
    </script>
</body>
</html>

  

posted @ 2020-06-25 21:54  小白咚  阅读(393)  评论(0编辑  收藏  举报