<div class="codetitle"> <span><a style="CURSOR: pointer" data="3342" class="copybut" id="copybut3342" onclick="doCopy('code3342')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code3342"> <br> <br><br> <br> <br><title></title> <br><script src="http://img.jb51.net/jslib/jquery/jquery-1.7.1.min.js" type="text/javascript"></script> <br><script type="text/javascript"> <BR>function showTime(tuanid, time_distance) { <BR>this.tuanid = tuanid; <BR>//PHP时间是秒,JS时间是微秒 <BR>this.time_distance = time_distance * 1000; <BR>} <BR>showTime.prototype.setTimeShow = function () { <BR>var timer = $("#lefttime_" + this.tuanid); <BR>var str_time; <BR>var int_day, int_hour, int_minute, int_second; <BR>time_distance = this.time_distance; <BR>this.time_distance = this.time_distance - 1000; <BR>if (time_distance > 0) { <BR>int_day = Math.floor(time_distance / 86400000); <BR>time_distance -= int_day * 86400000; <BR>int_hour = Math.floor(time_distance / 3600000); <BR>time_distance -= int_hour * 3600000; <BR>int_minute = Math.floor(time_distance / 60000); <BR>time_distance -= int_minute * 60000; <BR>int_second = Math.floor(time_distance / 1000); <BR>if (int_hour < 10) <BR>int_hour = "0" + int_hour; <BR>if (int_minute < 10) <BR>int_minute = "0" + int_minute; <BR>if (int_second < 10) <BR>int_second = "0" + int_second; <BR>str_time = int_day + "天" + int_hour + "小时" + int_minute + "分钟" + int_second + "秒"; <BR>timer.text(str_time); <BR>var self = this; <BR>setTimeout(function () { self.setTimeShow(); }, 1000); //D:正确 <BR>} else { <BR>timer.text("团购结束"); <BR>return; <BR>} <BR>} <BR></script> <br> <br> <br><div id="lefttime_1" time="2011/11/23 6:58:23"> <br><br> </div> <br><script type="text/javascript"> <BR>var st = new showTime(1,3); <BR>//st.tuanid = 1; <BR>//st.time_distance = 10000; <BR>st.setTimeShow(); <BR></script> <br><div id="lefttime_2" time="2011/11/24 6:58:23"> <br><br> </div> <br><script type="text/javascript"> <BR>var st = new showTime(2, 5); <BR>//st.tuanid = 1; <BR>//st.time_distance = 10000; <BR>st.setTimeShow(); <BR></script> <br> <br> <br> </div> <br>上面的代码需要用到jquery,大家可以注意下