2

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

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

4

1 回答 1

3

将以下代码放入问题的 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 的人愿意这样做,那将非常有帮助!

于 2014-04-27T01:35:43.163 回答