批量倒计时(可以参考下思路)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> </head> <style> div{position:relative;height:100px;} .the-time{position:absolute;} </style> <body> <div><p class="the-time" left_time="2018/9/9"> <strong></strong>天<strong></strong>小时<strong></strong>分钟<strong></strong>秒 </p></div> <div><p class="the-time" left_time="2017/11/12"> <strong></strong>天 <strong></strong>小时 <strong></strong>分钟 <strong></strong>秒 </p> </div> <div> <p class="the-time" left_time="2016/8/25 17:43:00"> <strong></strong>天 <strong></strong>小时 <strong></strong>分钟 <strong></strong>秒 </p> </div> <script> function setTimeP(p_class){ var ps = document.getElementsByTagName("p"); for(var i = 0; i < ps.length; i ++){ if(ps[i].className == p_class){ var aq_time = new Date(ps[i].getAttribute('left_time')); var now_time = new Date(); var end_time = parseInt((aq_time.getTime()-now_time.getTime())/1000); //var end_time = parseInt(ps[i].getAttribute('left_time')); //sdocument.write(end_time); if(end_time > 0){ ps[i].end_time = end_time; ps[i].t_ps = ps[i].getElementsByTagName("strong"); ps[i].timer = omg; ps[i].timer(); }else{ ps[i].innerHTML = "活动结束"; } } } function omg(){ if(this.end_time <= 0 ) return false this.end_time = this.end_time - 1; var left_d = Math.floor(this.end_time / 3600 / 24); var left_h = Math.floor((this.end_time / 3600)%24); var left_m = Math.floor(this.end_time % 3600 / 60); var left_s = this.end_time % 3600 % 60; this.t_ps[0].innerHTML = "还剩:"+left_d; this.t_ps[1].innerHTML = left_h; this.t_ps[2].innerHTML = left_m; this.t_ps[3].innerHTML = left_s; var _this = this; setTimeout(function(){_this.timer()}, 1000) } } </script> <SCRIPT LANGUAGE="JavaScript"> setTimeP("the-time"); </SCRIPT> </body> </html>