gpt4 book ai didi

javascript - 在 Qualtrics 调查中,如何使用 JavaScript 动态设置 slider 的范围?

转载 作者:行者123 更新时间:2023-11-29 19:40:37 25 4
gpt4 key购买 nike

我在 Qualtrics 中进行调查,需要让我的项目根据变量显示不同的 slider 值,在我的例子中,是来自循环和合并的值。这似乎不是你可以用管道文本做的事情,所以我不得不弄清楚如何在 Javascript 中做到这一点。

我发布此消息只是为了提供我自己找到的答案的机会。与 Qualtrics 一样,您的里程可能会有所不同,并且可能需要根据您的具体情况进行修改。特别是,问题 ID 和 postTag 的变化取决于它是否处于循环/合并中,可能还取决于其他因素。

最佳答案

将以下代码放入问题的 javascript 部分:

// Set the slider range
// First define the function to do it
setSliderRange = function (theQuestionInfo, maxValue) {
var postTag = theQuestionInfo.postTag
var QID=theQuestionInfo.QuestionID
// QID should be like "QID421"
// but postTag might be something like "5_QID421" sometimes
// or, it might not exist, so play around a bit.
var sliderName='CS_' + postTag
window[sliderName].maxValue=maxValue
// now do the ticks. first get the number of ticks by counting the table that contains them
var numTicks = document.getElementsByClassName('LabelDescriptionsContainer')[0].colSpan
// do the ticks one at a time
for (var i=1; i<=numTicks; i++) {
var tickHeader='header~' + QID + '~G' + i
// the first item of the table contains the minimum value, and also the first tick.
// so we do some tricks to separate them out in that case.
var tickSpanArray = $(tickHeader).down("span.TickContainer").children
var tickSpanArrayLength=tickSpanArray.length
var lastTickIndex=tickSpanArrayLength - 1
var currentTickValue = tickSpanArray[lastTickIndex].innerHTML
currentTickValue=currentTickValue.replace(/^\s+|\s+$/g,'')
console.log('Tick value ' + i + ' is ' + currentTickValue)
// now get the new value for the tick
console.log('maxValue: ' + maxValue + ' numTicks: ' + numTicks + ' i: ' + i)
var newTickValue = maxValue * i / numTicks //the total number of ticks
tickSpanArray[lastTickIndex].innerHTML=newTickValue.toString()
console.log('Changed tick value to ' + newTickValue)
}
}

var currentQuestionInfo = this.getQuestionInfo()
var currentQuestionID = currentQuestionInfo.QuestionID
// Now call the function
setSliderRange(currentQuestionInfo, theMaxValueYouWant)

如果您觉得我的回答有帮助,请帮助提高我的声誉,将“qualtrics”添加为有效标签!!或者,如果其他声望超过 1500 的人愿意这样做,那将非常有帮助!

关于javascript - 在 Qualtrics 调查中,如何使用 JavaScript 动态设置 slider 的范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23318397/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com