<div class="time countdown_1" data-time="1449429731"> <span class="t_h_1">00</span> <i class="lay_line">:</i> <span class="t_m_1">00</span> <i class="lay_line">:</i> <span class="t_s_1">00</span> </div> <div class="time countdown_2" data-time="1449456731"> <span class="t_h_2">00</span> <i class="lay_line">:</i> <span class="t_m_2">00</span> <i class="lay_line">:</i> <span class="t_s_2">00</span> </div>
//js2 var plugJs={ stamp:0, tid:1, stampnow:'<?php echo NOW_TIME;?>',//统一开始时间戳 intervalTime:function(){ if(plugJs.stamp > 0){ var day = Math.floor(plugJs.stamp / (60 * 60 * 24)); var hour = Math.floor(plugJs.stamp / (60 * 60)) - (day * 24); var minute = Math.floor(plugJs.stamp / 60) - (day * 24 * 60) - (hour * 60); var second = Math.floor(plugJs.stamp) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60); if (day <= 9) day = '0' + day; if (hour <= 9) hour = '0' + hour; if (minute <= 9) minute = '0' + minute; if (second <= 9) second = '0' + second; jQuery('.t_h_'+plugJs.tid).html(hour); jQuery('.t_m_'+plugJs.tid).html(minute); jQuery('.t_s_'+plugJs.tid).html(second); plugJs.stamp--; setTimeout('if(typeof(plugJs.intervalTime) == "function"){plugJs.intervalTime();}',1000); } }, timer:function (stampend,tid){ plugJs.stamp = parseInt(stampend)-parseInt(plugJs.stampnow);//剩余时间戳 setTimeout('if(typeof(plugJs.intervalTime) == "function"){plugJs.intervalTime();}',1000); } }; jQuery(document).ready(function(){ var stampend = parseInt(jQuery('.countdown_1').attr('data-time'));//灵活读取表里的结束时间戳 plugJs.timer(stampend,'1'); });