• 时间(时分秒)


    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="utf-8">
    <title>无标题文档</title>
    <script>
    function toDou(n)
    {
        if(n<10)
        {
            return '0'+n;//判断是否小于10 如果小于在前面加0,把一个数字给他补0变成两位数例如05 
        }
        else
        {
            return ''+n;//前面加空格让其返回字符串
        }
    }
    
    window.onload=function ()
    {
        var aImg=document.getElementsByTagName('img');
        
        function tick(){
            var oDate=new Date();
            
            var str=toDou(oDate.getHours())+toDou(oDate.getMinutes())+toDou(oDate.getSeconds());
            
            for(var i=0;i<aImg.length;i++)
            {
                aImg[i].src='img/'+str.charAt(i)+'.png';//设置图片路径 charAt方法 获取字符串上的某一位东西 让其兼容ie
            }
        }
        setInterval(tick, 1000);
        tick();
    };
    </script>
    </head>
    <body style="background:black; color: white; font-size:50px;">
    <img src="img/0.png" />
    <img src="img/0.png" />
    :
    <img src="img/0.png" />
    <img src="img/0.png" />
    :
    <img src="img/0.png" />
    <img src="img/0.png" />
    </body>
    </html>
  • 相关阅读:
    计算机基础(7)
    计算机基础(6)
    计算机基础(5)
    计算机基础(4)
    计算机基础(3)
    计算机基础(2)
    计算机基础(1)
    数组、函数
    js基础知识
    随笔3
  • 原文地址:https://www.cnblogs.com/Xuman0927/p/6026521.html
Copyright © 2020-2023  润新知