How to get the TD having the rowspan with value and split into individual td using jquery?

前端 未结 1 1746
粉色の甜心
粉色の甜心 2021-01-24 03:51

I have a table containing rowspan (Merged Rows), I need to split that merged rows into individuals and put the rowspan value in last td.

NOTE: In my cod

相关标签:
1条回答
  • 2021-01-24 04:30

    Try this:

    $('table td').each(function() {
        var _parent_tr = $(this).parent();
        var rowspan = $(this).attr('rowspan');
        var rowspanVal = $(this).attr('rowspan');
        $(this).removeAttr('rowspan');
        if (rowspan && rowspan>1) {
         for(var i=1;i<=rowspan;i++){
         	_parent_tr.append("<td>"+rowspanVal+"</td>");
         }
        }
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <table border="1" cellpadding="2" cellspacing="0" id="0" style="border-collapse: collapse;" class="dataTable">          
     <tbody>
     <tr style="height:15.0pt;">
      <td><input type="checkbox" id="row_0" class="dt-checkboxes_1" value=""></td>
      <td class="td_0_2" rowspan="2">#<input type="checkbox" id="td_0" class="hrchy-dt-checkboxes" value=""></td>
      <td class="td_0_2">&nbsp;</td>
      <td class="td_0_2">&nbsp;</td>
      <td class="td_0_3">(Invested Assets)</td>
      <td class="td_0_3">(Admitted Assets)</td>
      <td class="td_0_4">Pasivos (Liabilities)</td>
      <td class="td_0_4">Pasivos (Liabilities)</td>
      <td class="td_0_4">Pasivos (Liabilities)</td>
      <td class="td_0_4">Pasivos (Liabilities)</td>
      <td class="td_0_4">Pasivos (Liabilities)</td>
      <td class="td_0_4">Pasivos (Liabilities)</td>
     </tr>
     <tr style="height:15.0pt;">
      <td><input type="checkbox" id="row_1" class="dt-checkboxes_1" value=""></td>
      <td class="td_0_3">(NAIC Code)<input type="checkbox" id="td_1" class="hrchy-dt-checkboxes" value=""></td>
      <td class="td_0_3">( Domestics Insurers)</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td class="td_0_3">(Aggregate Reserve for Life Contracts)</td>
      <td class="td_0_3">(Reserve for Life Contract Claims)</td>
      <td class="td_0_6">(Aggregate Reserve for Accident and Health Contract Claims)</td>
      <td class="td_0_6">(Reserve for Accident and Health Contracts Claims)</td>
      <td class="td_0_3">(Other Liabilities)**</td>
      <td class="td_0_3">(Total Liabilities)</td>
     </tr>
     </tbody>
     </table>

    0 讨论(0)
提交回复
热议问题