今天学到了一个倒计时效果,本人脑子有点慢,琢磨了半天时间。做完之后给乱码看了下,学到了 一个知识点 x|0 取x整数 ,再此感谢乱码。
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <title>leftTime</title> <meta name="description" content=""> <meta name="keywords" content=""> <link href="" rel="stylesheet"> <script type="text/javascript"> var interval = 1000; function countDown(year,month,day,divname){ var nowTime = new Date(); var endTime = new Date(year,month-1,day); var leftTime =endTime.getTime()-nowTime.getTime(); var leftSecondes = parseInt(leftTime/1000); var day1 = leftSecondes/(60*60*24) | 0; var hours = (leftSecondes - day1*60*60*24 ) / 3600 | 0 ; var minute = (leftSecondes - day1*60*60*24 - hours*3600)/60 | 0; var secondes = (leftSecondes - day1*60*60*24 - hours*3600 -minute*60) | 0; var oDemo = document.getElementById(divname); oDemo.innerHTML = "距离婚纱照:"+year+"年"+month+"月"+day+"日还有 "+day1+"天"+hours+"时"+minute+"分钟"+secondes+"秒"; } window.setInterval(function(){ countDown(2014,7,25,‘demo‘) },interval) </script> </head> <body> <div id="demo"></div> </body> </html>
原文:http://www.cnblogs.com/1989zhiyuan/p/3790619.html