如何让TD具有值的rowspan并使用jquery分成单独的td?

时间:2017-08-28 12:27:35

标签: jquery

我有一个包含rowspan(Merged Rows)的表,我需要将合并的行拆分为个体,并将rowspan值放在最后一个td中。

注意:在我的代码中,我只针对最后一个拥有Rowspan的td,但我需要动态

这是我的jquery:

 $('table td').each(function() {
    var $firstTr = $('table tr:first');
    var $lastTd = $firstTr.children('td:last');
    var rowspan = $lastTd.attr('rowspan');
    $lastTd.removeAttr('rowspan');
    if (rowspan && rowspan>1) {
      $firstTr.nextAll('tr').each(function(i) {
        if (i==rowspan-2) {
          $(this).append($lastTd.clone());
          return false;
        }
        else {
          $(this).append($('<td>'));
        }
      });
      $lastTd.html('');
    }
});

我的HTML:

<table border="1" cellpadding="2" cellspacing="0" id="0" style="border-collapse: collapse;" class="dataTable">          
 <tbody>
 <tr style="height:15.0pt;"><input type="checkbox" id="row_0" class="dt-checkboxes_1" value=""> 
  <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;"><input type="checkbox" id="row_1" class="dt-checkboxes_1" value=""> 
  <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>

更新:

enter image description here

这里的表有rowspan,其中包含值'#'和'(Domestic Insures)',这就是我需要分开的内容。

enter image description here

我在分离rowspan后期待上述结果。

感谢您的帮助,提前致谢

更新HTML:

<table border="1" cellpadding="2" cellspacing="0" id="0" style="border-collapse: collapse;">          
 <tr style="height:15.0pt;"> 
  <td class="td_0_2" rowspan="2">#</td>
  <td class="td_0_2">&nbsp;</td>
  <td class="td_0_3" rowspan="2">( Domestics Insurers)</td>
  <td class="td_0_4">(Invested Assets)</td>
  <td class="td_0_4">(Admitted Assets)</td>
  <td class="td_0_5" colspan="6">Pasivos (Liabilities)</td>
  <td class="td_0_6">(Capital Stock)***</td>
  <td class="td_0_4">(Gross Paid in and Contributed Surplus)</td>
  <td class="td_0_4">(Surplus Note)</td>
  <td class="td_0_6">(Surplus Special Funds)</td>
  <td class="td_0_6">(Unassigned Surplus)</td>
  <td class="td_0_6">(Capital and Surplus)</td>
  <td class="td_0_4">(Puerto Rico Statutory Deposit)</td> 
 </tr> 
 <tr style="height:15.0pt;"> 
  <td class="td_0_4">(NAIC Code)</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td class="td_0_4">(Aggregate Reserve for Life Contracts)</td>
  <td class="td_0_4">(Reserve for Life Contract Claims)</td>
  <td class="td_0_7">(Aggregate Reserve for Accident and Health Contract Claims)</td>
  <td class="td_0_7">(Reserve for Accident and Health Contracts Claims)</td>
  <td class="td_0_4">(Other Liabilities)**</td>
  <td class="td_0_4">(Total Liabilities)</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td> 
 </tr> 
 <tr style="height:15.0pt;"> 
  <td class="td_0_8">1</td>
  <td class="td_0_3">73156</td>
  <td class="td_0_2">Caribbean American Life Assurance Company</td>
  <td class="td_0_8">37005870</td>
  <td class="td_0_8">39121913</td>
  <td class="td_0_8">10657732</td>
  <td class="td_0_8">549535</td>
  <td class="td_0_8">10477380</td>
  <td class="td_0_8">1228042</td>
  <td class="td_0_8">4939305</td>
  <td class="td_0_8">27851994</td>
  <td class="td_0_8">2600000</td>
  <td class="td_0_8">2770165</td>
  <td class="td_0_8">-</td>
  <td class="td_0_8">-</td>
  <td class="td_0_8">5899754</td>
  <td class="td_0_8">11269919</td>
  <td class="td_0_8">2235000</td> 
 </tr> 
 <tr style="height:15.0pt;"> 
  <td class="td_0_9">2</td>
  <td class="td_0_10">79715</td>
  <td class="td_0_11">Cooperativa de Seguros de Vida de Puerto Rico, COSVI</td>
  <td class="td_0_9">375733934</td>
  <td class="td_0_9">521919288</td>
  <td class="td_0_9">307950083</td>
  <td class="td_0_9">3309541</td>
  <td class="td_0_9">13587652</td>
  <td class="td_0_9">5527606</td>
  <td class="td_0_9">169350874</td>
  <td class="td_0_9">499725756</td>
  <td class="td_0_9">-</td>
  <td class="td_0_9">-</td>
  <td class="td_0_9">6001002</td>
  <td class="td_0_9">51165920</td>
  <td class="td_0_9">-34973390</td>
  <td class="td_0_9">22193532</td>
  <td class="td_0_9">5250000</td> 
 </tr> 
 <tr style="height:15.0pt;"> 
  <td class="td_0_9">3</td>
  <td class="td_0_10">47085</td>
  <td class="td_0_11">Delta Dental of Puerto Rico, Inc.</td>
  <td class="td_0_9">22403611</td>
  <td class="td_0_9">26523710</td>
  <td class="td_0_9">-</td>
  <td class="td_0_9">-</td>
  <td class="td_0_9">-</td>
  <td class="td_0_9">335000</td>
  <td class="td_0_9">5943469</td>
  <td class="td_0_9">6278469</td>
  <td class="td_0_9">8000000</td>
  <td class="td_0_9">9019528</td>
  <td class="td_0_9">-</td>
  <td class="td_0_9">-</td>
  <td class="td_0_9">3243873</td>
  <td class="td_0_9">20245241</td>
  <td class="td_0_9">500000</td> 
 </tr> 
 <tr style="height:15.0pt;"> 
  <td class="td_0_9">4</td>
  <td class="td_0_10">84603</td>
  <td class="td_0_11">Humana Insurance of Puerto Rico, Inc.</td>
  <td class="td_0_9">61141921</td>
  <td class="td_0_9">67281619</td>
  <td class="td_0_9">-</td>
  <td class="td_0_9">8542</td>
  <td class="td_0_9">42000</td>
  <td class="td_0_9">9268932</td>
  <td class="td_0_9">11731600</td>
  <td class="td_0_9">21051074</td>
  <td class="td_0_9">2500026</td>
  <td class="td_0_9">-</td>
  <td class="td_0_9">-</td>
  <td class="td_0_9">-</td>
  <td class="td_0_9">43730519</td>
  <td class="td_0_9">46230545</td>
  <td class="td_0_9">1500000</td> 
 </tr> 
 <tr style="height:15.0pt;"> 
  <td class="td_0_9">5</td>
  <td class="td_0_10">77054</td>
  <td class="td_0_11">MAPFRE Life Insurance Company of Puerto Rico</td>
  <td class="td_0_9">53134284</td>
  <td class="td_0_9">60468252</td>
  <td class="td_0_9">8117726</td>
  <td class="td_0_9">652516</td>
  <td class="td_0_9">6958049</td>
  <td class="td_0_9">10742972</td>
  <td class="td_0_9">14518999</td>
  <td class="td_0_9">40990262</td>
  <td class="td_0_9">3032000</td>
  <td class="td_0_9">40413146</td>
  <td class="td_0_9">-</td>
  <td class="td_0_9">-</td>
  <td class="td_0_9">-23967156</td>
  <td class="td_0_9">19477990</td>
  <td class="td_0_9">1250000</td> 
 </tr> 
 <tr style="height:15.0pt;"> 
  <td class="td_0_9">6</td>
  <td class="td_0_10">60030</td>
  <td class="td_0_11">MCS Life Insurance Company</td>
  <td class="td_0_9">49398875</td>
  <td class="td_0_9">68708634</td>
  <td class="td_0_9">-</td>
  <td class="td_0_9">250000</td>
  <td class="td_0_9">-</td>
  <td class="td_0_9">27056822</td>
  <td class="td_0_9">20850625</td>
  <td class="td_0_9">48157447</td>
  <td class="td_0_9">2500000</td>
  <td class="td_0_9">7760000</td>
  <td class="td_0_9">-</td>
  <td class="td_0_9">-</td>
  <td class="td_0_9">10291187</td>
  <td class="td_0_9">20551187</td>
  <td class="td_0_9">1254196</td> 
 </tr> 
 <tr style="height:15.0pt;"> 
  <td class="td_0_9">7</td>
  <td class="td_0_10">72087</td>
  <td class="td_0_11">Multinational Life Insurance Company</td>
  <td class="td_0_9">103377545</td>
  <td class="td_0_9">112798823</td>
  <td class="td_0_9">68629125</td>
  <td class="td_0_9">700945</td>
  <td class="td_0_9">14483339</td>
  <td class="td_0_9">2602907</td>
  <td class="td_0_9">9103845</td>
  <td class="td_0_9">95520161</td>
  <td class="td_0_9">4741720</td>
  <td class="td_0_9">16622090</td>
  <td class="td_0_9">5000000</td>
  <td class="td_0_9">-</td>
  <td class="td_0_9">-9085148</td>
  <td class="td_0_9">17278662</td>
  <td class="td_0_9">2980000</td> 
 </tr> 
 <tr style="height:15.0pt;"> 
  <td class="td_0_9">8</td>
  <td class="td_0_10">12952</td>
  <td class="td_0_11">Pan American Life Insurance Company of Puerto Rico</td>
  <td class="td_0_9">7310626</td>
  <td class="td_0_9">7891777</td>
  <td class="td_0_9">1334</td>
  <td class="td_0_9">29450</td>
  <td class="td_0_9">140382</td>
  <td class="td_0_9">1711264</td>
  <td class="td_0_9">1027723</td>
  <td class="td_0_9">2910153</td>
  <td class="td_0_9">2500000</td>
  <td class="td_0_9">4663068</td>
  <td class="td_0_9">-</td>
  <td class="td_0_9">-</td>
  <td class="td_0_9">-2181444</td>
  <td class="td_0_9">4981624</td>
  <td class="td_0_9">1428739</td> 
 </tr> 
 <tr style="height:15.0pt;"> 
  <td class="td_0_9">9</td>
  <td class="td_0_10">69523</td>
  <td class="td_0_11">Trans-Oceanic Life Insurance Company</td>
  <td class="td_0_9">66000321</td>
  <td class="td_0_9">70576913</td>
  <td class="td_0_9">3813436</td>
  <td class="td_0_9">80542</td>
  <td class="td_0_9">20950958</td>
  <td class="td_0_9">5565000</td>
  <td class="td_0_9">7320475</td>
  <td class="td_0_9">37730411</td>
  <td class="td_0_9">2500000</td>
  <td class="td_0_9">50000</td>
  <td class="td_0_9">-</td>
  <td class="td_0_9">-</td>
  <td class="td_0_9">30296502</td>
  <td class="td_0_9">32846502</td>
  <td class="td_0_9">1306000</td> 
 </tr> 
 <tr style="height:15.0pt;"> 
  <td class="td_0_9">10</td>
  <td class="td_0_10">55816</td>
  <td class="td_0_11">Triple-S Salud, Inc.</td>
  <td class="td_0_9">483733846</td>
  <td class="td_0_9">701075752</td>
  <td class="td_0_9">-</td>
  <td class="td_0_9">-</td>
  <td class="td_0_9">85555</td>
  <td class="td_0_9">216404347</td>
  <td class="td_0_9">113429330</td>
  <td class="td_0_9">329919232</td>
  <td class="td_0_9">149999640</td>
  <td class="td_0_9">-</td>
  <td class="td_0_9">-</td>
  <td class="td_0_9">-</td>
  <td class="td_0_9">221156880</td>
  <td class="td_0_9">371156520</td>
  <td class="td_0_9">600000</td> 
 </tr> 
 <tr style="height:15.0pt;"> 
  <td class="td_0_9">11</td>
  <td class="td_0_10">73814</td>
  <td class="td_0_11">Triple-S Vida, Inc.</td>
  <td class="td_0_9">547337102</td>
  <td class="td_0_9">601800264</td>
  <td class="td_0_9">426537041</td>
  <td class="td_0_9">8457757</td>
  <td class="td_0_9">48125623</td>
  <td class="td_0_9">24840796</td>
  <td class="td_0_9">31801549</td>
  <td class="td_0_9">539762766</td>
  <td class="td_0_9">3000000</td>
  <td class="td_0_9">22060000</td>
  <td class="td_0_9">5750000</td>
  <td class="td_0_9">-</td>
  <td class="td_0_9">31227498</td>
  <td class="td_0_9">62037498</td>
  <td class="td_0_9">2105000</td> 
 </tr> 
 <tr style="height:15.0pt;"> 
  <td class="td_0_9">12</td>
  <td class="td_0_10">60041</td>
  <td class="td_0_11">Universal Life Insurance Company</td>
  <td class="td_0_9">505004694</td>
  <td class="td_0_9">1137449441</td>
  <td class="td_0_9">239203640</td>
  <td class="td_0_9">3052642</td>
  <td class="td_0_9">2372657</td>
  <td class="td_0_9">1538551</td>
  <td class="td_0_9">822806872</td>
  <td class="td_0_9">1068974362</td>
  <td class="td_0_9">2500000</td>
  <td class="td_0_9">22391608</td>
  <td class="td_0_9">-</td>
  <td class="td_0_9">-</td>
  <td class="td_0_9">43583471</td>
  <td class="td_0_9">68475079</td>
  <td class="td_0_9">1594460</td> 
 </tr> 
 <tr style="height:15.0pt;"> 
  <td class="td_0_6">13</td>
  <td class="td_0_7">11067</td>
  <td class="td_0_4">USIC Life Insurance Company</td>
  <td class="td_0_6">9648806</td>
  <td class="td_0_6">9942341</td>
  <td class="td_0_6">59589</td>
  <td class="td_0_6">62746</td>
  <td class="td_0_6">771060</td>
  <td class="td_0_6">487110</td>
  <td class="td_0_6">789331</td>
  <td class="td_0_6">2169836</td>
  <td class="td_0_6">4000000</td>
  <td class="td_0_6">4000000</td>
  <td class="td_0_6">-</td>
  <td class="td_0_6">-</td>
  <td class="td_0_6">-227495</td>
  <td class="td_0_6">7772505</td>
  <td class="td_0_6">1250000</td> 
 </tr> 
 <tr style="height:15.0pt;"> 
  <td class="td_0_12">&nbsp;</td>
  <td class="td_0_13">&nbsp;</td>
  <td class="td_0_13">TOTAL</td>
  <td class="td_0_14">2321231435</td>
  <td class="td_0_14">3425558727</td>
  <td class="td_0_14">1064969706</td>
  <td class="td_0_14">17154216</td>
  <td class="td_0_14">117994655</td>
  <td class="td_0_14">307309349</td>
  <td class="td_0_14">1213613997</td>
  <td class="td_0_14">2721041923</td>
  <td class="td_0_14">187873386</td>
  <td class="td_0_14">129749605</td>
  <td class="td_0_14">16751002</td>
  <td class="td_0_14">51165920</td>
  <td class="td_0_14">318995051</td>
  <td class="td_0_14">704516804</td>
  <td class="td_0_15">23253395</td> 
 </tr>   
</table>

1 个答案:

答案 0 :(得分:1)

试试这个:

&#13;
&#13;
$('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>");
     }
    }
});
&#13;
<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>
&#13;
&#13;
&#13;