首页 > 编程 > JavaScript > 正文

JS小功能(setInterval实现图片效果显示时间)实例代码

2019-11-20 21:34:01
字体:
来源:转载
供稿:网友

效果:

代码:

复制代码 代码如下:

<head runat="server">
    <title></title>
    <script type="text/javascript">
        function toDou(n) {
            if (n < 10) {
                return '0' + n;
            }
            else {
                return '' + n;
            }
        }
        setInterval(
        window.onload = function () {
            var aImg = document.getElementsByTagName('img');
            var oDate = new Date();
            var str = toDou(oDate.getHours()) + toDou(oDate.getMinutes()) + toDou(oDate.getSeconds());
            for (var i = 0; i < str.length; i++) {
                aImg[i].src = 'Images/Number1/' + str[i] + '.jpg';
            }
        }, 1000);

    </script>
</head>
<body style="background-color: Black;">
    <div style="text-align: center; line-height: 600px">
        <img src="Images/Number1/0.jpg" /><img src="Images/Number1/0.jpg" /><span style="font-size: 77px;
            color: White; text-align: center; line-height: 2px;">:</span><img src="Images/Number1/0.jpg" /><img
                src="Images/Number1/0.jpg" /><span style="font-size: 77px; color: White;">:</span><img
                    src="Images/Number1/0.jpg" /><img src="Images/Number1/0.jpg" />
    </div>
</body>

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表