• Javascript倒计时


    <!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>
      <title> new document </title>
      <meta name="generator" content="editplus" />
      <meta name="author" content="" />
      <meta name="keywords" content="" />
      <meta name="description" content="" />
      <meta http-equiv="content-type" content="text/htm;charset=utf-8" />
     </head>
    
     <body>
      <div>
    	距离广州亚运会开幕时间2010年11月12还有:<span id="otherTime"></span>
      </div>
    <script type="text/javascript">
    	var objElem = document.getElementById("otherTime");
    
    	var endTime = new Date('2010', '10', '12').getTime();
    
    	var nowTime = null;
    	var laveTimer = null;
    
    	function laveTime() {
    		nowTime = new Date().getTime();
    
    		var a = endTime - nowTime;//距离指定的时间还有多少毫秒..
    
    		if (a > 0) {
    			
    			var arr_1 = [1000*60*60*24, 1000*60*60, 1000*60, 1000],
    				arr_2 = ['天', '小时', '分', '秒'],
    				temp = null;
    			
    			var timeDesArr = [];
    
    			for (var i = 0, len = arr_1.length; i<len ; i++) {
    				temp = Math.floor(a/arr_1[i]);
    
    				if (temp > 0) {
    					timeDesArr.push((String(temp).length == 1 ? ("00"+temp).substr(1) : temp) + arr_2[i]);
    				}
    				
    				a -= arr_1[i]*temp;
    			}
    
    			objElem.innerHTML = timeDesArr.join("");
    
    		} else {
    			objElem.innerHTML = "到时间了!";
    			clearInterval(laveTime);
    			laveTime = null;
    		}
    	}
    	
    	//因为我们的时候是一秒一秒的在走,那么也需要一秒一秒的改变一下这个剩余时间了,一秒执行一次laveTime函数
    	laveTimer = setInterval(laveTime, 1*1000);
    </script>
    
     </body>
    </html>
    
     
     
    运行示例代码:
  • 相关阅读:
    游标
    Linq to Sql学习
    在asp.net mvc中使用Uploadify上传文件
    Linq 笔记
    ASP.NET MVC笔记
    转:ASP.NET MVC:窗体身份验证及角色权限管理示例
    PowerDesigner
    asp.net缓存使用总结
    Bash Shell中命令行选项/参数处理
    Javascript parseFloat、parseDouble类型转换,数值加减,四舍五入
  • 原文地址:https://www.cnblogs.com/meteoric_cry/p/1824732.html
Copyright © 2020-2023  润新知