到目前为止,到目前为止,我已经能够将表行与td中的文本合并,但是textarea中的文本尚未通过。我的桌子

Column1 | column2 | column3 | Column4
--------------------------------------
 Assay  |  Source | label  |   3%
-------------------------------------
 Assay  |  Source | label  |   10%
-------------------------------------


我想完成什么

Column1 | column2 | column3 | Column4
--------------------------------------  //Note that Column1 has
        |        |         |   3%       //no textarea, just td text
 Assay  - Source -   label -----------  //While all the rest have
        |        |         |   10%      //textareas in the tds
-------------------------------------   // from column 2 - 4


我有此代码仅适用于不带textareas的tds。如何合并文本区域具有相同数据的行?

function merge() {
  $('.result_table').each(function() {
    var Column_number_to_Merge = 1;

    // Previous_TD holds the first instance of same td. Initially first TD=null.
    var Previous_TD = null;
    var i = 1;
    $("tbody", this).find('tr').each(function() {
      // find the correct td of the correct column
      // we are considering the table column 1, You can apply on any table column
      var Current_td = $(this).find('td:nth-child(' + Column_number_to_Merge + ')');

      if (Previous_TD == null) {
        // for first row
        Previous_TD = Current_td;
        i = 1;
      } else if (Current_td.text() == Previous_TD.text()) {
        // the current td is identical to the previous row td
        // remove the current td
        Current_td.remove();
        // increment the rowspan attribute of the first row td instance
        Previous_TD.attr('rowspan', i + 1);
        i = i + 1;
      } else {
        // means new value found in current td. So initialize counter variable i
        Previous_TD = Current_td;
        i = 1;
      }
    });
  });
}


的HTML

<table class="table table-condensed col-md-12 result_table">
  <thead style="border:solid black 1px;">
    <td class="side">TEST</td>
    <td class="tdbold">METHOD</td>
    <td class="tdbold">COMPENDIA</td>
    <td class="tdbold">SPECIFICATION</td>
    <td class="tdbold">DETERMINED</td>
    <td class="side">REMARKS</td>
  </thead>
  <tbody>
    <tr valign="middle" align="center">
      <td style="font-size:13px; " class="tbody_data side" rowspan="2">Assay</td>
      <td valign="middle" align="center" style="padding: 0px;" class="tbody_data">
        <input type="hidden" value="6" name="tests[]">
        <textarea style="border: medium none; vertical-align: middle; height: 79px;" class="det_st form-control">HPLC</textarea>
      </td>
      <td style="padding: 0px;" class="tbody_data">
        <textarea style="border: medium none; height: 79px;" class="det_st form-control">Adopted In-House Method</textarea>
      </td>
      <td style="padding: 0px;" class="tbody_data">
        <textarea style="border: medium none; height: 79px;" class="det_st form-control">92.5 - 107.5%</textarea>
      </td>
      <td style="padding: 0px;" class="tbody_data">
        <textarea style="border: medium none; height: 82px;" class="det_st form-control">Day 1 105.3% (RSD=1.5%; n=6)</textarea>
      </td>
      <td class="tbody_data side">
        <select style="border:none; margin:15px; width:145px;" class="select" selected="selected">
          <option value="COMPLIES">COMPLIES</option>
          <option value="COMPLIES">COMPLIES</option>
          <option value="DOES NOT COMPLY">DOES NOT COMPLY</option>
        </select>
      </td>
    </tr>

    <tr valign="middle" align="center">

      <td valign="middle" align="center" style="padding: 0px;" class="tbody_data">
        <input type="hidden" value="6" name="tests[]">
        <textarea style="border: medium none; vertical-align: middle; height: 79px;" class="det_st form-control">HPLC</textarea>
      </td>
      <td style="padding: 0px;" class="tbody_data">
        <textarea style="border: medium none; height: 79px;" class="det_st form-control">Adopted In-House Method</textarea>
      </td>
      <td style="padding: 0px;" class="tbody_data">
        <textarea style="border: medium none; height: 79px;" class="det_st form-control">92.5 - 107.5%</textarea>
      </td>
      <td style="padding: 0px;" class="tbody_data">
        <textarea style="border: medium none; height: 102px;" class="det_st form-control">Day 7 102.9% (RSD=0.27%; n=6)</textarea>
      </td>
      <td class="tbody_data side">
        <select style="border:none; margin:15px; width:145px;" class="select" selected="selected">
          <option value="COMPLIES">COMPLIES</option>
          <option value="COMPLIES">COMPLIES</option>
          <option value="DOES NOT COMPLY">DOES NOT COMPLY</option>
        </select>
      </td>
    </tr>
  </tbody>
</table>

最佳答案

我不确定您要做什么,但是看起来像这样:

if (Current_td.text() == Previous_TD.text())


可以更改为:

 if (Current_td.text() == Previous_TD.text()
      || Current_td.find("textarea").val() == Previous_TD.find("textarea").val())

08-25 13:37