http://jsfiddle.net/zAFND/640/
在jsfiddle我有,我遇到的问题是响应时间。它上升了2秒而不是1秒。我认为这个问题是因为我有两个问题所以它计算每个响应时间文本输入中两个问题的秒数,因此每次上升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);
`
答案 0 :(得分:4)
移动
的var声明response = "00:00:00",
responseparts = response.split(':'),
responsehours = +responseparts[0],
responseminutes = +responseparts[1],
responseseconds = +responseparts[2];
在每个回调中
此外,将您的ck-button ID更改为类。 Id的意思是独特的。