$(function(){ updateEndTime(); }); function updateEndTime() { var date = new Date(); var time = date.getTime(); $(".settime").each(function(i) { var endDate = new Date(this.getAttribute("endTime")); var endTime = endDate.getTime(); var lag = (endTime - time) / 1000; if (lag > 0) { var second = Math.floor(lag % 60); var minite = Math.floor((lag / 60) % 60); var hour = Math.floor((lag / 3600) % 24); var day = Math.floor((lag / 3600) / 24); $(this).html(day + "天" + hour + "小时" + minite + "分" + second + "秒"); }else{ $(this).html("团购已经结束啦!"); } }); setTimeout("updateEndTime()", 1000) }; </script>
??<div class="time fl settime" endTime="unix时间">时间</div>