要求:在某div中显示离某时间的倒计时程序,显示“XX分xx秒”,每秒刷新一次。时间到0后,自动提交表单。
网上查的都是各种花哨的,我只要功能,不求花,程序简单点的。

解决方案 »

  1.   

      <div id="hxtime" style="padding:5px 0 0 0;width:680px; height:1%; margin:10px auto;border:1px solid blue; "></div>   function ShowTimes(){  
        LeaveTime = AfterTime - new Date();  
        LeaveDays=Math.floor(LeaveTime/(1000*60*60*24));//天  
        LeaveHours=Math.floor(LeaveTime/(1000*60*60)%24);//时  
        LeaveMinutes=Math.floor(LeaveTime/(1000*60)%60);//分  
        LeaveSeconds=Math.floor(LeaveTime/1000%60);//秒        document.getElementById("hxtime").innerHTML="距离下班还有<font color=red>"+LeaveHours+"</font>时<font color=red>"+LeaveMinutes+"</font>分<font color=red>"+LeaveSeconds+"</font>秒";  
    }  
    var AfterTime= new Date();
    AfterTime.setHours(18,0,0,0);  
    setInterval(ShowTimes,100);  
      

  2.   

    setInterval(ShowTimes,1000); // 每秒刷新一次