我有一个Qualtrics survey包含一些自定义JavaScript的问题(启用带有两个滑块旋钮的滑块)。我可以a)复制调查以及b)将调查导出为.qsf文件并重新导入。在这两种情况下,我都会进行一项新的工作调查。
但是,使用"从......导入问题"将调查问题导入现有调查。功能不起作用; JavaScript无法在这种情况下工作。有没有办法在保留JavaScript时将这些问题导入现有调查?
第一个(最相关)问题中使用的代码:
Qualtrics.SurveyEngine.addOnload(function()
{
document.getElementById("QR~QID7").setAttribute("readonly", "readonly");
document.getElementById("QR~QID8").setAttribute("readonly", "readonly");
var surface;
var cnst = 4;
// Sets the sliders parameters and starting values
$("#research-slider").slider({ id: "research-slider", min: 0, max: 10, range: true, value: [0, 10]});
// variable to store in surface area when user has stopped sliding
var surface, currentResponse;
$("#research-slider").on("slideStop", function(slideEvt) {
surface = slideEvt.value;
document.getElementById("minimum").innerHTML = surface[0];
document.getElementById("maximum").innerHTML = surface[1];
document.getElementById("newValue").innerHTML = (surface[1]- surface[0])/cnst ;
document.getElementById("QR~QID7").value = surface[0];
document.getElementById("QR~QID8").value = surface[1];
});
$('NextButton').onclick = function (event) {
// and now run the event that the normal next button is supposed to do
Qualtrics.SurveyEngine.navClick(event, 'NextButton')
}
})
答案 0 :(得分:4)
导入时JavaScript不起作用,因为您使用的是固定QID代码(QID7和QID8)。解决方案是编写代码以通过遍历DOM来查找正确的元素。最简单的方法是使用prototypejs而不是原生JavaScript。
假设min(QID7)和max(QID8)紧跟在您的代码附加的问题之后,那么它将类似于:
var qid = this.questionId;
var min = $(qid).next('.QuestionOuter').down('.InputText');
var max = $(qid).next('.QuestionOuter',1).down('.InputText');
min.setAttribute("readonly", "readonly");
max.setAttribute("readonly", "readonly");
var surface;
var cnst = 4;
// Sets the sliders parameters and starting values
$("#research-slider").slider({ id: "research-slider", min: 0, max: 10, range: true, value: [0, 10]});
// variable to store in surface area when user has stopped sliding
var surface, currentResponse;
$("#research-slider").on("slideStop", function(slideEvt) {
surface = slideEvt.value;
$("minimum").innerHTML = surface[0];
$("maximum").innerHTML = surface[1];
$("newValue").innerHTML = (surface[1]- surface[0])/cnst ;
min.value = surface[0];
max.value = surface[1];
});