根据您的需求,修改后的代码如下:

let th = $("#th").val();
let tmmc = $("#tmmc").val();
let tt = $(".tt").val();
let vote_vid = "";
let subject_sid = "";

$.ajax({
  async: false,
  url: "/getSubject",
  type: "get",
  dataType: "json",
  data: {
    subject_stype: th,
    subject_scontent: tmmc,
    vote_vid: vote_vid
  },
  success: function (data) {
    console.log(data);

    $.ajax({
      async: false,
      url: "/getAnswer",
      type: "get",
      dataType: "json",
      data: {
        answer_acontent: tt,
        subject_sid: subject_sid
      },
      success: function (data) {
        console.log(data);
        for (let i = 0; i < data.length; i++) {
          let tr = $("<tr></tr>");
          let td1 = $("<td></td>");
          let td2 = $("<td></td>");
          let td3 = $("<td></td>");

          td1.html("【<input type=\"text\" id=\"th\" style=\"border: none;width: 50px; color: #00a2d4\" disabled=\"disabled\">】\n" +
            "<input type=\"text\" id=\"tmmc\" style=\"border: none;\" disabled=\"disabled\">");

          if (data[i].subject_stype === "t") {
            td2.html("<input type=\"radio\" class='xx' name=\"ch\"><input type=\"text\" class='tt' style=\"border: none;\" disabled=\"disabled\" >");
            td3.html("<input type=\"radio\" class='xx' name=\"ch\"><input type=\"text\" class='ttt' style=\"border: none;\" disabled=\"disabled\" >");
          } else if (data[i].subject_stype === "x") {
            td2.html("<input type=\"checkbox\" class='xx' name=\"ra\"><input type=\"text\" class='tt' style=\"border: none;\" disabled=\"disabled\" >");
            td3.html("<input type=\"checkbox\" class='xx' name=\"ra\"><input type=\"text\" class='ttt' style=\"border: none;\" disabled=\"disabled\" >");
          }

          tr.append(td1);
          tr.append(td2);
          tr.append(td3);

          $("#tab").append(tr);
        }
      }
    })
  }
});

这个修改后的代码将根据返回的数据来动态生成<tr>元素,并根据subject_stype的值来决定生成单选题还是多选题的输入框


原文地址: https://www.cveoy.top/t/topic/ieGk 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录