在 qualtrics 上使用 javascript:循环块中的问题 ID
using javascript on qualtrics: questions ids in looped blocks
我正在使用以下代码修改表单答案:
$('QR~QID24~1').insert({after: ' out of'});
$('QR~QID24~2').style.position = "relative";
$('QR~QID24~2').style.left = "100px";
$('QR~QID24~2').style.bottom = "34.5px";
这不再有效,因为当块循环时,问题重复五次,名称如下:
QR~1_QID24~1
QR~2_QID24~1
QR~3_QID24~1
QR~4_QID24~1
QR~5_QID24~1
我试着用每个名字重复代码:
$('QR~1_QID24~1').insert({after: ' out of'});
$('QR~1_QID24~2').style.position = "relative";
$('QR~1_QID24~2').style.left = "100px";
$('QR~1_QID24~2').style.bottom = "34.5px";
$('QR~2_QID24~1').insert({after: ' out of'});
$('QR~2_QID24~2').style.position = "relative";
$('QR~2_QID24~2').style.left = "100px";
$('QR~2_QID24~2').style.bottom = "34.5px";
等等...但那是行不通的。
我已经看过但无法找到解决循环块中问题识别的方法。
试试这个:
var qid = this.questionId;
$('QR~'+qid+'~1').insert({after: ' out of'});
$('QR~'+qid+'~2').style.position = "relative";
$('QR~'+qid+'~2').style.left = "100px";
$('QR~'+qid+'~2').style.bottom = "34.5px";
我认为您的解决方案不起作用,因为每个页面上只存在一些元素,所以不存在的元素会导致错误。您必须在每个语句前放置一个 if 语句以避免错误。
仅作记录。这种情况下的最终解决方案涉及获取 PostTag 代码,该代码在每个循环中都会发生变化。
var currentPostTag = this.getPostTag();
$('QR~'+currentPostTag+'~1').insert({after: ' out of'});
$('QR~'+currentPostTag+'~2').style.position = "relative";
$('QR~'+currentPostTag+'~2').style.left = "90px";
$('QR~'+currentPostTag+'~2').style.bottom = "28px";
我正在使用以下代码修改表单答案:
$('QR~QID24~1').insert({after: ' out of'});
$('QR~QID24~2').style.position = "relative";
$('QR~QID24~2').style.left = "100px";
$('QR~QID24~2').style.bottom = "34.5px";
这不再有效,因为当块循环时,问题重复五次,名称如下:
QR~1_QID24~1
QR~2_QID24~1
QR~3_QID24~1
QR~4_QID24~1
QR~5_QID24~1
我试着用每个名字重复代码:
$('QR~1_QID24~1').insert({after: ' out of'});
$('QR~1_QID24~2').style.position = "relative";
$('QR~1_QID24~2').style.left = "100px";
$('QR~1_QID24~2').style.bottom = "34.5px";
$('QR~2_QID24~1').insert({after: ' out of'});
$('QR~2_QID24~2').style.position = "relative";
$('QR~2_QID24~2').style.left = "100px";
$('QR~2_QID24~2').style.bottom = "34.5px";
等等...但那是行不通的。 我已经看过但无法找到解决循环块中问题识别的方法。
试试这个:
var qid = this.questionId;
$('QR~'+qid+'~1').insert({after: ' out of'});
$('QR~'+qid+'~2').style.position = "relative";
$('QR~'+qid+'~2').style.left = "100px";
$('QR~'+qid+'~2').style.bottom = "34.5px";
我认为您的解决方案不起作用,因为每个页面上只存在一些元素,所以不存在的元素会导致错误。您必须在每个语句前放置一个 if 语句以避免错误。
仅作记录。这种情况下的最终解决方案涉及获取 PostTag 代码,该代码在每个循环中都会发生变化。
var currentPostTag = this.getPostTag();
$('QR~'+currentPostTag+'~1').insert({after: ' out of'});
$('QR~'+currentPostTag+'~2').style.position = "relative";
$('QR~'+currentPostTag+'~2').style.left = "90px";
$('QR~'+currentPostTag+'~2').style.bottom = "28px";