Qualtrics 中并排问题类型的列自动求和

问题描述 投票:0回答:0
Qualtrics.SurveyEngine.addOnload(function() {
  var table = document.getElementById("tableID"); // replace "tableID" with the actual ID of your table
  var numRows = table.rows.length;
  var numCols = table.rows[0].cells.length;
  
  // create a new row at the bottom of the table
  var newRow = table.insertRow(numRows);
  
  // loop through each column and calculate the total
  for (var j = 1; j < numCols; j++) { // start from 1 to skip the header cell
    var total = 0;
    for (var i = 1; i < numRows - 1; i++) { // start from 1 to skip the header row, end before the last row
      var cell = table.rows[i].cells[j];
      var input = cell.getElementsByTagName("input")[0];
      if (input.type == "text" || input.type == "number") {
        total += parseFloat(input.value);
      }
    }
    
    // add the total to the new row
    var newCell = newRow.insertCell(j);
    newCell.innerHTML = total;
  }
});

我对 Java Script 的了解为零,我想将 Java 脚本添加到 Qualtrics 中并排问题的选项中。任何人都可以帮助我获得正确的代码,我已经尝试了很多事情似乎没有任何效果,因为我不了解它

我尝试了互联网和 ChatGPT 上可用的不同代码,似乎没有任何方法可以解决我的问题`

javascript jquery javascript-objects qualtrics
© www.soinside.com 2019 - 2024. All rights reserved.