倒计时

 1     var aInp = document.getElementsByTagName('input');
 2     var iNow = null;
 3     var iNew = null;
 4     var t = 0;
 5     var str = '';
 6     var timer = null;
 7     
 8     aInp[2].onclick = function () {
 9         iNew = new Date(aInp[0].value);
10         clearInterval( timer );
11         
12         timer = setInterval (function (){
13             
14             iNow = new Date();
15             t = Math.floor( ( iNew - iNow ) / 1000 );
16             
17             if ( t >= 0 ) {
18                 
19                 str = Math.floor(t/86400)+'天'+Math.floor(t%86400/3600)+'时'+Math.floor(t%86400%3600/60)+'分'+t%60+'秒';
20             
21                 aInp[1].value = str;
22                 
23             } else {
24                 
25                 clearInterval( timer );
26                 
27             }
28         
29         }, 1000);
30     };
原文地址:https://www.cnblogs.com/frontendnotes/p/6432018.html