http://jsfiddle.net/zAFND/640/

在jsfiddle中,我遇到的问题是响应时间。上升了2秒,而不是1秒。我认为这是因为我有2个问题,所以它在每个响应时间文本输入中都计算了两个问题的秒数,因此每次都增加2秒。但是我的问题是如何解决这个问题,以便计时器正常计数:

响应时间代码:

`
     var response =“ 00:00:00”,
         responseparts = response.split(':'),
         responsehours = + responseparts [0],
         responseminutes = + responseparts [1],
         responseseconds = + responseparts [2];

     function correctResponse(responsenum) {
         return (responsenum < 10) ? ("0" + responsenum) : responsenum;
     }

 var responsetimer = [];
 $('.queWrap').each(function(index, element) {
 var wrap=$(this),
 input = wrap.find('.responseTime'),
 checkbox=wrap.find('#ck-button').find('input'),
 clickInput=wrap.find('.mouseClick');


     responsetimer[index] = setInterval(function () {
     responseseconds++;
     if (responseseconds == 60) {
         responseseconds = 00;
         responseminutes++;

         if (responseminutes == 60) {
             responseminutes = 00;
             responsehours++;

             if (responsehours <= 24) {
                 clearInterval(responsetimer);
                 return;
             }

         }
     }
     input.val(correctResponse(responsehours) + ":" + correctResponse(responseminutes) + ":" + correctResponse(responseseconds));
 }, 1000);


`

最佳答案

移动的var声明

response = "00:00:00",
responseparts = response.split(':'),
responsehours = +responseparts[0],
responseminutes = +responseparts[1],
responseseconds = +responseparts[2];


在每个回调中

http://jsfiddle.net/h8srH/1/

另外,将您的ck按钮ID更改为class。 ID是唯一的。

07-24 15:34