Qualtrics 受访者的“添加选择”按钮不起作用

问题描述 投票:0回答:1

我在此线程上使用了有用的代码:Qualtrics 中受访者的“添加选择”按钮

代码:

var that=this.questionId;
    jQuery("#"+this.questionId+" tr.ChoiceRow:not(:lt(1))").hide();
    jQuery("<input type='button' id='add' value='Add field' name='+' />").insertAfter("#"+this.questionId+" tr.ChoiceRow:last");
    jQuery("#add").on('click',function(){
        var c= jQuery("tr.ChoiceRow:visible").length;
        jQuery("#"+that+" tr.ChoiceRow:eq("+c+")").show(); 
    });

我正在使用此代码来解决同一页面上的两个问题(下面的屏幕截图)。但是,如果我对第一个问题添加 2 个回答,它会为下一个问题生成 2 个表单字段。

代码似乎正在输入/链接到下一个问题?我怎样才能避免这种情况,以便受访者可以做出组合反应?

谢谢大家!

// 期望代码单独运行

javascript button addition survey qualtrics
1个回答
0
投票

元素 id (id='add') 在页面上必须是唯一的。使用类来代替:

var that=this.questionId;
jQuery("#"+this.questionId+" tr.ChoiceRow:not(:lt(1))").hide();
jQuery("<input type='button' class='add' value='Add field' name='+' />").insertAfter("#"+this.questionId+" tr.ChoiceRow:last");
jQuery("#"+this.questionId+" .add").on('click',function(){
    var c= jQuery("tr.ChoiceRow:visible").length;
    jQuery("#"+that+" tr.ChoiceRow:eq("+c+")").show(); 
});
© www.soinside.com 2019 - 2024. All rights reserved.