在qualtrics上使用javascript:循环块中的问题ID
我正在使用以下代码修改表单答案:在qualtrics上使用javascript:循环块中的问题ID,javascript,qualtrics,Javascript,Qualtrics,我正在使用以下代码修改表单答案: $('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
$('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";