• 简陋时钟


    1:charAt() 方法可返回指定位置的字符。

    2:获取时间:getHours(),getMinutes(),geFullYear(),getDay()(返回星期几,0-6),getDate(),getMouth()(0-11)

     1 <!doctype html>
     2 <html>
     3 <head>
     4     <meta charset="UTF-8">
     5     <script type="text/javascript" >
     6     //将单位数转换成双位
     7     function toDouble(num){
     8         if(num<10)
     9             return '0'+num;
    10         else
    11             return num;
    12     }
    13     //更新时间
    14     function timeUpdate(){
    15         var oDate=new Date();
    16         var imgS=document.getElementsByTagName('img');
    17         var str=''+toDouble(oDate.getHours())+toDouble(oDate.getMinutes())+toDouble(oDate.getSeconds());
    18         var i=0;
    19         for(i=0;i<imgS.length;i++)
    20         {
    21             imgS[i].src="images/"+str.charAt(i)+".png";
    22         }
    23     }
    24     window.onload=function(){
    25         //设置定时器,每一秒更新一次,但若只是这样,会在页面加载1s后才更新时间
    26         setInterval(timeUpdate,1000);
    27         //页面一加载就调用更新函数,因此不会有1s延迟
    28         timeUpdate();
    29 
    30     };
    31     </script>
    32     <style>
    33     body{
    34         background-color:orange;
    35         font-size:30px; 
    36     }
    37     </style>
    38 </head>
    39 <img src="images/0.png">
    40 <img src="images/0.png">
    41 42 <img src="images/0.png">
    43 <img src="images/0.png">
    44 45 <img src="images/0.png">
    46 <img src="images/0.png">
    47 48 <body>
    49 </body>
    50 </html>

  • 相关阅读:
    Android 屏幕实现水龙头事件
    高速排序算法
    hdu2993坡dp+二进制搜索
    如何设计接口?
    virtio-netdev 发送数据包
    android-sdk-windows下载版
    FusionCharts简明教程(一)---建立FusionCharts图形
    strcpy_s与strcpy对照
    安全博客
    图片相关
  • 原文地址:https://www.cnblogs.com/l0520/p/6809865.html
Copyright © 2020-2023  润新知