Home > Web Front-end > JS Tutorial > Make a clock with JS

Make a clock with JS

不言
Release: 2018-04-10 11:52:19
Original
2013 people have browsed it

This article introduces the code about using JS to make a clock. Now I share it with everyone. Friends in need can refer to it


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="系统CSS初始化.css">
    <style>       ul{           height: 100px;           width: 600px;           margin: 200px auto;
       }        img{            float:left;
        }        span{            font-size: 100px;            float: left;            display: block;            position: relative;            bottom: 20px;
        }
    </style>
    <script>        window.onload=function ()
        {            function setDoub(n) {                if(n<10)
                {
                    n=&#39;0&#39;+n;
                }                else                {
                    n=&#39;&#39;+n;
                }                return n;
            }            var aImg=document.getElementsByTagName("img");            function tick() {                var date=new Date();                var str=setDoub(date.getHours())+setDoub(date.getMinutes())+setDoub(date.getSeconds());                for(var i=0;i<aImg.length;i++)
                {                    aImg[i].src="images/"+str[i]+".png";
                }
            }           tick();            setInterval(tick,1000)
        }
    </script>
</head>
<body>
    <ul id="ul1">
    <img src="images/0.png">
    <img src="images/0.png">
        <span>:</span>
    <img src="images/0.png">
    <img src="images/0.png">
        <span>:</span>
    <img src="images/0.png">
    <img src="images/0.png">
    </ul>

</body>
</html>
Copy after login

The above is the detailed content of Make a clock with JS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template