日期:2014-05-16  浏览次数:20394 次

倒计时js

?? ??? 在页面的产品促销需要用到倒计时,

HTML如下:

<span id="pad" class="font18red">

?js如下:

<script language="javascript"> 
		var startDate = new Date($!dateMillisecond);
		var endDate = new Date($!millisecond1);
		var spantime = (endDate - startDate)/1000;
		var expireDaysTemp = $!expireDays;
		function cal(){
			 spantime --;
			 var h = Math.floor((spantime % (24*3600))/3600);
			 var m = Math.floor((spantime % 3600)/(60));
			 var s = Math.floor(spantime%60);
			 if((h+"").length==1){
				h = "0" + h;
			 }
			  if((m+"").length==1){
			 	m = "0" + m;
			 }
			  if((s+"").length==1){
				s = "0" + s;
			 }
			  str = h + ":" + m + ":" + s;
		          document.getElementById("pad").innerHTML = str;
	                  if(expireDaysTemp==0&&h==0&&m==0&&s==0){
			     	document.getElementById("LimitedTimeOffers").style.display = "none";
		          }
	      }	
		window.onload = function(){
		 	  setInterval(cal, 1000);
	        }
 </script>

?

。。。