我想实现一个由用户输入时间,比如说是(2012-04-11 15:20:15)然后就在页面的右上角对这个时间动态累加,比如说5秒后就显示(2012-04-11 15:20:20),这个该怎么实现呢?请前辈们提供下思路,谢谢!或者有类似的js时间插件可以,谢谢大家了~~~

解决方案 »

  1.   

    <!doctype html>
    <html>  
        <head>  
            <title>tank fighting</title>  
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
            
        </head>  
        <body>
         <div id="showDIV"></div>
         <input id="inputbox" type="text" value="" />
         <input id="startBtn" type="button" value="Start" />
         <input id="stopBtn" type="button" value="Stop" />
            <script>
             var timer;
             document.getElementById('startBtn').onclick = function(){
             var inputbox = document.getElementById('inputbox'),
             baseTime = new Date(inputbox.value).getTime(),
             orginal = new Date().getTime(),
             time,
             showTime,
             div = document.getElementById('showDIV');
             timer = setInterval(function(){
             time = new Date().getTime();
             showTime = new Date(time - orginal + baseTime);
             div.innerHTML = showTime;
             }, 1000);
             };
             document.getElementById('stopBtn').onclick = function(){
             clearInterval(timer);
             };
            </script>  
        </body>  
    </html>