现在,当您查看 jsfiddledemo 时,我遇到的问题是,如果您在其中一个文本输入(问题 1)中输入一个数字,它会进行计算,但它会在列中以不同的方式显示答案。
假设在您输入数字 2 的顶部文本输入中,它应该显示“剩余标记 3”,但它会删除“剩余标记”txt 并仅显示数字 3(也不是粗体)。
所以我的问题是,为什么在显示计算答案时会改变远端列的格式?
下面是jquery函数:
查询:
    $(function () {
        //alert("here");         
        var questions = $('#markstbl td[class*="_ans"]').length - 1;
        //disable single entry
        for (var i = 0; i <= questions; i++) {
            if ($("[class*=q" + i + "_mark]").length == 1) {
                var t_marks = $("[class*=q" + i + "_ans]").html();
                //alert(t_marks);
                $("[class*=q" + i + "_mark]").val(t_marks)
                    .attr("disabled", "disabled");
                //$("[class*=q"+i+"_mark]").attr("disabled","disabled");
            }
        }
        //find each question set and add listeners
        for (var i = 0; i <= questions; i++) {
            $('input[class*="q' + i + '"]').keyup(function () {
                var cl = $(this).attr('class').split(" ")[1]
                var questionno = cl.substring(cl.indexOf('q') + 1, cl.indexOf('_'));
                var tot_marks = $(".q" + questionno + "_ans_org").val();
                //alert(tot_marks);
                var ans_t = 0;
                $("[class*=q" + questionno + "_mark]").each(function () {
                    var num = (isNaN(parseInt($(this).val()))) ? 0 : parseInt($(this).val());
                    ans_t += parseInt(num);
                });
                ans_t = tot_marks - ans_t;
                //alert(ans_t);
                //var fixedno = tot_marks;
                var ans = (parseInt(ans_t) < 0) ? tot_marks : ans_t;
                $(".q" + questionno + "_ans").val(ans);
                $(".q" + questionno + "_ans_text").html(ans);
            });
        }
    });
下面是动态 HTML 表:
HTML:
  <body>
  <table border='1' id='markstbl'>
    <thead>
      <tr>
        <th class='questionth'>Question No.</th>
        <th class='questionth'>Question</th>
        <th class='answerth'>Answer</th>
        <th class='answermarksth'>Marks per Answer</th>
        <th class='noofmarksth'>Total Marks Remaining</th>
      </tr>
    </thead>
    <tbody>
      <?php
      $row_span  = array_count_values($searchQuestionId);
      $prev_ques = '';
      foreach ($searchQuestionId as $key => $questionId) {
      ?>
      <tr class="questiontd">
        <?php
            if ($questionId != $prev_ques) {
        ?>
        <td class="questionnumtd" name="numQuestion" rowspan=
        "<?php echo $row_span[$questionId]; ?>"><?php
                echo $questionId;
        ?><input type="hidden" name="q<?php echo $questionId; ?>_ans_org" class=
        "q<?php echo $questionId; ?>_ans_org" value=
        "<?php echo $searchMarks[$key]; ?>" /><input type="hidden" name=
        "q<?php echo $questionId; ?>_ans" class=
        "q<?php echo $questionId; ?>_ans" value=
        "<?php echo $searchMarks[$key]; ?>" /></td>
        <td class="questioncontenttd" rowspan="<?php echo $row_span[$questionId]; ?>">
        <?php
                echo $searchQuestionContent[$key];
        ?></td><?php
            }
        ?>
        <td class="answertd" name="answers[]"><?php
            echo $searchAnswer[$key];
        ?></td>
        <td class="answermarkstd"><input class=
        "individualMarks q<?php echo $questionId; ?>_mark_0" q_group="1" name=
        "answerMarks[]" id="individualtext" type="text" /></td><?php
            if ($questionId != $prev_ques) {
        ?>
        <td class="noofmarkstd q<?php echo $questionId; ?>_ans_text" q_group="1"
        rowspan="<?php echo $row_span[$questionId]; ?>"><?php
                echo $searchMarks[$key];
        ?></td><?php
            }
        ?>
      </tr><?php
          $prev_ques = $questionId;
      }
      ?>
    </tbody>
  </table>
</body>
更新:
以下是页面第一次打开时的样子:

当我在文本输入中输入数字并进行计算并在最后一列显示答案时,您可以在下面看到右侧最后一列的变化:
