Qualtrics,Javascript:如何实现暂停并显示之前隐藏的选项?
Qualtrics, Javascript: how to implement a pause and show previously hidden choices?
我设计了一个新的调查,在我的一个多项选择题中,备选方案应该隐藏 1 秒,这样用户在回答之前就倾向于花更多的注意力在问题上。
到目前为止,我的代码只能隐藏选项,但仍然缺少等待和显示。 (下面的代码)
感谢您提供有关如何解决此问题的任何帮助或建议。
Qualtrics.SurveyEngine.addOnload(function () {
this.hideNextButton();
this.hideChoices();
//HERE I WOULD LIKE THE CODE TO WAIT FOR 1 sec
//HERE I WOULD LIKE THE CHOICES TO REAPPEAR ON THE SCREEN
this.questionclick = function (event, element) {
if (this.getChoiceValue(4) == true) {
this.clickNextButton();
} else if (this.getChoiceValue(5) == true) {
this.clickNextButton();
}
}
});
这里有两部分问题。
- 如何等一秒?这是通过
setTimeout()
和回调函数完成的。
- 如何确保回调函数作用于正确的对象? - 这是通过将我们要处理的对象存储在变量中来完成的。
因此,在不了解 Qualtrics SurveyEngine 的情况下,从您的代码中可以清楚地看出 onLoad
回调中的 this
指的是您的调查对象。我们稍后会在 setTimeout
回调中需要该对象,所以让我们存储它。剩下的就简单了:
Qualtrics.SurveyEngine.addOnload(function () {
var survey = this;
// attach click event handler
self.questionclick = function (event, element) {
// using `survey` instead of `this` would work here, too
if (this.getChoiceValue(4) || this.getChoiceValue(5)) {
this.clickNextButton();
}
};
// hide buttons
survey.hideNextButton();
survey.hideChoices();
// after 1000ms, show buttons again
setTimeout(function () {
survey.showNextButton();
survey.showChoices();
}, 1000);
});
我设计了一个新的调查,在我的一个多项选择题中,备选方案应该隐藏 1 秒,这样用户在回答之前就倾向于花更多的注意力在问题上。 到目前为止,我的代码只能隐藏选项,但仍然缺少等待和显示。 (下面的代码)
感谢您提供有关如何解决此问题的任何帮助或建议。
Qualtrics.SurveyEngine.addOnload(function () {
this.hideNextButton();
this.hideChoices();
//HERE I WOULD LIKE THE CODE TO WAIT FOR 1 sec
//HERE I WOULD LIKE THE CHOICES TO REAPPEAR ON THE SCREEN
this.questionclick = function (event, element) {
if (this.getChoiceValue(4) == true) {
this.clickNextButton();
} else if (this.getChoiceValue(5) == true) {
this.clickNextButton();
}
}
});
这里有两部分问题。
- 如何等一秒?这是通过
setTimeout()
和回调函数完成的。 - 如何确保回调函数作用于正确的对象? - 这是通过将我们要处理的对象存储在变量中来完成的。
因此,在不了解 Qualtrics SurveyEngine 的情况下,从您的代码中可以清楚地看出 onLoad
回调中的 this
指的是您的调查对象。我们稍后会在 setTimeout
回调中需要该对象,所以让我们存储它。剩下的就简单了:
Qualtrics.SurveyEngine.addOnload(function () {
var survey = this;
// attach click event handler
self.questionclick = function (event, element) {
// using `survey` instead of `this` would work here, too
if (this.getChoiceValue(4) || this.getChoiceValue(5)) {
this.clickNextButton();
}
};
// hide buttons
survey.hideNextButton();
survey.hideChoices();
// after 1000ms, show buttons again
setTimeout(function () {
survey.showNextButton();
survey.showChoices();
}, 1000);
});