日期:2014-05-16 浏览次数:21809 次
var B='2012-01-11 09:14:00' var E='2012-01-11 09:15:00' var D='2012-01-11 09:15:00' // obj 为显示的倒计时容器 // 结果:00:01:00 // 倒计时完毕 (00:00:00)停止 // 可调用回调函数 function A(B,E,obj){ } function B(B,D,obj){ } function A1(B,E,obj,CallBack){ } function B1(B,D,obj,CallBack){ }
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>new document</title> </head> <body> <div id="timer"></div> <script type="text/javascript"> var B='2012-01-11 09:14:00' var E='2012-01-11 09:15:00' var D='2012-01-11 09:15:00' function A(st, ed, el, callback){ el = document.getElementById(el); st = new Date(st.replace(/-/g, "/")); ed = new Date(ed.replace(/-/g, "/")); var sp = ed - st; (function(){ var d = new Date(sp); el.innerHTML = ("0" + d.toLocaleTimeString()).replace(/^08/, "00"); if(sp > 0){ setTimeout(arguments.callee, 1000); }else if(callback){ callback(); } sp -= 1000; })(); } A(B, D, "timer", function(){alert(1);}); </script> </body> </html>