zoukankan      html  css  js  c++  java
  • 时钟制作

    首先需要10张图片,上面是分别是0-9的数字,获得时间,将时间变为字符串,在循环,让相应的图片显示,达到时钟的目的,需要用到定时器

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>定时时钟</title>
    
    <script>
    function toDou(n){//将编程字符串
    	if(n<10){
    		return '0'+n;//例如03
    	}else{
    		return ''+n;//例如11
    	}
    }
    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());
    		//str='311232';//将当前的时分秒变为相应的字符串
    		for(var i=0;i<aImg.length;i++){//for循环,根据字符串各位的数字变换相应的图像
    			aImg[i].src='img/'+str[i]+'.png';
    		}
    		
    	}
    	setInterval(tick,1000);//一秒执行一次,变一次图片
    	tick();//先执行函数,可以避免刷新时全变为0
    }</script>
    </head>
    
    <body style="background:#0F0; color:#FC0; 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>
    
  • 相关阅读:
    Hadoop1.2.0开发笔记(四)
    Datalist、GridView、Repeater 的区别
    oAuth
    浏览器沙箱技术
    28个HTML5特征、窍门和技术
    在Windows 8 JavaScript Metro Application 开发
    CSS浮动属性Float详解
    Windows 8为什么会是开发人员的2012
    CSS实现截取隐藏文字
    国外可绑定域名的免费空间(精选)
  • 原文地址:https://www.cnblogs.com/lzzhuany/p/4590656.html
Copyright © 2011-2022 走看看