码迷,mamicode.com
首页 > Web开发 > 详细

JS 倒计时实现代码(时、分,秒)

时间:2017-12-17 13:21:29      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:win   interval   doctype   val   day   doc   date   script   utf-8   

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
<title>JS实现倒计时(时、分,秒)</title> 
<script language="javascript" type="text/javascript"> 
var interval = 1000; 
function ShowCountDown(year,month,day,divname) 
{ 
var now = new Date(); 
var endDate = new Date(year, month-1, day); 
var leftTime=endDate.getTime()-now.getTime(); 
var leftsecond = parseInt(leftTime/1000); 
//var day1=parseInt(leftsecond/(24*60*60*6)); 
var day1=Math.floor(leftsecond/(60*60*24)); 
var hour=Math.floor((leftsecond-day1*24*60*60)/3600); 
var minute=Math.floor((leftsecond-day1*24*60*60-hour*3600)/60); 
var second=Math.floor(leftsecond-day1*24*60*60-hour*3600-minute*60); 
var cc = document.getElementById(divname); 
cc.innerHTML = "脚本之家提示距离"+year+""+month+""+day+"日还有:"+day1+""+hour+"小时"+minute+""+second+""; 
} 
window.setInterval(function(){ShowCountDown(2018,1,5,divdown1);}, interval); 
</script> 
</head> 
<body> 
<div id="divdown1"></div> 
</body> 
</html> 

 

JS 倒计时实现代码(时、分,秒)

标签:win   interval   doctype   val   day   doc   date   script   utf-8   

原文地址:http://www.cnblogs.com/chenmiaosong/p/8051658.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!