倒计时
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>无标题文档</title> <style> .t1 { width:400px; } </style> <script> window.onload = function () { var aInp = document.getElementsByTagName('input'); var iNow = null; var iNew = null; var t = 0; var str = ''; var timer = null; aInp[2].onclick = function () { iNew = new Date(aInp[0].value); //获取填写设定的时间 clearInterval( timer ); timer = setInterval (function (){ iNow = new Date(); //得到现在的时间 t = Math.floor( ( iNew - iNow ) / 1000 ); //得到距离设定的时间还有多少秒 if ( t >= 0 ) { //如果是正数,继续倒计时 str = Math.floor(t/86400)+'天'+Math.floor(t%86400/3600)+'时'+Math.floor(t%86400%3600/60)+'分'+t%60+'秒'; aInp[1].value = str; } else { //如果是负数说明已经到了时间,停止倒计时 clearInterval( timer ); } }, 1000); }; }; </script> </head> <body> 距离:<input class="t1" type="text" value="November 27,2013 22:3:0" /><br /> 还剩:<input class="t1" type="text" /> <input type="button" value="开始倒计时吧" /> </body> </html>