function countDown(time, fn) { var maxtime = (new Date(time) - new Date()) / 1000;//剩余秒 var timer = setInterval(function () { if (maxtime >= 0) { var dd = parseInt(maxtime / 60 / 60 / 24, 10);//计算剩余的天数 var hh = parseInt(maxtime / 60 / 60 % 24, 10);//计算剩余的小时数 var mm = parseInt(maxtime / 60 % 60, 10);//计算剩余的分钟数 var ss = parseInt(maxtime % 60, 10);//计算剩余的秒数 hh = checkTime(hh); mm = checkTime(mm); ss = checkTime(ss); msg = "剩余时间 " + dd + "天" + hh + "时" + mm + "分" + ss + "秒"; fn(msg); --maxtime; } else { clearInterval(timer); fn("已结束"); } }, 1000);}function checkTime(i) { if (i < 10) { i = "0" + i; } return i;}/*使用方法<script type="text/javascript"> countDown('2015-5-29 10:40:44', function (msg) { $('#time_1').text(msg); }); </script> */
新闻热点
疑难解答