Javascript Qualtrics:动态设置加载时的滑块最大值

Javascript Qualtrics:动态设置加载时的滑块最大值,javascript,jquery,slider,qualtrics,Javascript,Jquery,Slider,Qualtrics,我正在进行一项调查,要求根据对前一个问题的回答设置Qualtrics HSlider的最大范围。我可以通过管道将问题的结果设置为当前值,但不能设置最大值 我看了其他的问题 这还没有解决办法,所以我想我会再次问这个问题,看看最近是否有人解决了这个问题。我发现的最接近的错误是:“无法设置undefined的属性'maxValue'”。查看其他各种文档,主要问题似乎不是存在单个slider类,而是组成slider的div标记集合 谢谢你的帮助 编辑:这是我一直在尝试使用的代码,但我认为它不会工作,因为

我正在进行一项调查,要求根据对前一个问题的回答设置Qualtrics HSlider的最大范围。我可以通过管道将问题的结果设置为当前值,但不能设置最大值

我看了其他的问题 这还没有解决办法,所以我想我会再次问这个问题,看看最近是否有人解决了这个问题。我发现的最接近的错误是:“无法设置undefined的属性'maxValue'”。查看其他各种文档,主要问题似乎不是存在单个slider类,而是组成slider的div标记集合

谢谢你的帮助

编辑:这是我一直在尝试使用的代码,但我认为它不会工作,因为缺少一个独特的滑块对象

Qualtrics.SurveyEngine.addOnload(function()
{
    // 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)
        }
    }
    console.log(this.getQuestionInfo());
    var currentQuestionInfo = this.getQuestionInfo();
    var currentQuestionID = currentQuestionInfo.QuestionID;
    var Q8Response = parseInt("${q://QID8/ChoiceTextEntryValue}");
    // Now call the function
    setSliderRange(currentQuestionInfo, Q8Response)

});

Qualtrics.SurveyEngine.addOnReady(function()
{
    /*Place your JavaScript here to run when the page is fully displayed*/

});

Qualtrics.SurveyEngine.addOnUnload(function()
{
    /*Place your JavaScript here to run when the page is unloaded*/

});
Qualtrics.SurveyEngine.addOnload(函数()
{
//设置滑块范围
//首先定义要执行此操作的函数
setSliderRange=函数(问题信息,最大值){
var postTag=theQuestionInfo.postTag
var QID=theQuestionInfo.QuestionID
//QID应该像“QID421”
//但postTag有时可能类似于“5_QID421”
//或者,它可能不存在,所以玩一玩。
var sliderName='CS_'+postTag
窗口[sliderName].maxValue=maxValue
//现在做记号。首先通过计算包含记号的表来获得记号的数量
var numTicks=document.getElementsByClassName('LabelDescriptionsContainer')[0]。colSpan
//一次做一个滴答声

对于(var i=1;iPretty很难调试您的问题,但无法看到您正在使用的代码。我将代码添加到原始帖子中。我认为它的方向根本不对,因为我认为Qualtrics现在处理滑块的方式找不到实际的滑块对象。它们似乎只是一个集合n个HTML DIV标记和侦听器。