0

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);

`

4

1 回答 1

4

移动 var 声明

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

在每个回调中

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

此外,将您的 ck-button id 更改为 classes。ID 是唯一的。

于 2013-02-10T04:23:46.947 回答