我正在使用以下代码修改表单答案:
$('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";
等等…但这根本不起作用。我已经看过了,但没能找到一个解决方案来识别循环块中的问题。
仅供记录。这种情况下的最终解决方案包括获取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";
试试这个:
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语句,以避免出现错误。