用javascript 做时间倒数,倒数时间

某个试卷在线考试需要读秒。网上找了一会就是没找到我想要的。只好自己改改网上的,这也用用,那也用用。

其他代码不贴了。贴相关的:

html页面代码:

<a class="btn btn-default" onclick="StartExamine();">开始</a> 
<div id="TimeClock"  class="col-md-4" ><span class="text-danger hour">00</span> <span class="text-danger minute">00</span> <span class="text-danger seconds">00</span></div>
作为一个显示倒数的div层

javascript 代码:

 
 var gEaminePapeId = 'dfdfad33434342';
        var gExaminePapeTime = '100';        
        var gHour = gExaminePapeTime / 60;        
        var gMinute = gExaminePapeTime % 60; 
        var gSeconds = gExaminePapeTime * 60;
        var hour_elem = $("#TimeClock").find('.hour');
        var minute_elem = $("#TimeClock").find('.minute');
        var second_elem = $("#TimeClock").find('.seconds');
        function StartExamine() { 
           //开始计时           
            var timeClik = setInterval('ShowClock()', 1000);
      }
      function ShowClock() {        
          if (gSeconds > 1) {
              gSeconds -= 1;
              var hour = Math.floor((gSeconds / 3600) % 24);
              var minute = Math.floor((gSeconds / 60) % 60);
              var second = Math.floor(gSeconds % 60);
              $(hour_elem).text(hour < 10 ? "0" + hour+":" : hour+":"); //计算小时
              $(minute_elem).text(minute < 10 ? "0" + minute+":" : minute+":"); //计算分钟
              $(second_elem).text(second < 10 ? "0" + second : second); //计算秒杀
          }
          else {
              clearInterval(timeClik);
              //做题时间到
               ForceSubmit();
          }
      }     
        function ForceSubmit() {
            //强制提交答题
        }




你可能感兴趣的:(JavaScript,html,jquery,倒数计数器)