我使用以下代码在qualtrics块中实现计时器:
Qualtrics.SurveyEngine.addOnload(function()
{
var headerCont = document.createElement("div");
headerCont.className = "header-cont";
headerCont.id = "header_container";
var header = document.createElement("div");
header.className = "header"
header.id = "header_1";
var timer = document.createElement("div");
timer.className = "timer";
timer.id = "timer_1";
timer.innerHTML = "Time Remaining: <span id='time'>02:00</span>";
headerCont.appendChild(header);
header.appendChild(timer);
document.body.insertBefore(headerCont, document.body.firstChild)
function startTimer(duration, display) {
var timer = duration, minutes, seconds;
var myTimer = setInterval(function() {
minutes = parseInt(timer / 60, 10)
seconds = parseInt(timer % 60, 10);
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
var text = ('innerText' in display)? 'innerText' : 'textContent';
display[text] = minutes + ":" + seconds;
if (--timer < 0) {
clearInterval(myTimer);
timeOver();
}
}, 1000);
}
var timerSeconds = 120,
display = document.querySelector('#time');
startTimer(timerSeconds, display);
var timeOver = function(
{Qualtrics.SurveyEngine.setEmbeddedData("blockTimeFlag", "1");
$('NextButton').click();
document.getElementById("timer_1").innerHTML = "Time is up.";}
});
但是,如果参与者在计时器尝试之前继续(我想允许),计时器会继续并在时间到时自动进入下一页,这是我不想要的。因此,我想&#34;删除&#34;单击下一个按钮后立即执行计时器。不幸的是,实现一个额外的页面并压制下一个按钮以强制等待时间到了。
如果有人可以提供帮助,那会很棒!