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

我有一个包含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($('')); } }); $lastTd.html(''); } }); 

我的HTML:

 
#     (Invested Assets) (Admitted Assets) Pasivos (Liabilities)Pasivos (Liabilities)Pasivos (Liabilities)Pasivos (Liabilities)Pasivos (Liabilities)Pasivos (Liabilities)
(NAIC Code) ( Domestics Insurers)     (Aggregate Reserve for Life Contracts) (Reserve for Life Contract Claims) (Aggregate Reserve for Accident and Health Contract Claims) (Reserve for Accident and Health Contracts Claims) (Other Liabilities)** (Total Liabilities)

更新:

在此处输入图像描述

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

在此处输入图像描述

在分离rowspan之后,我期待上面的结果。

感谢帮助,提前致谢

更新HTML:

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

试试这个:

 $('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(""+rowspanVal+""); } } }); 
  
#     (Invested Assets) (Admitted Assets) Pasivos (Liabilities) Pasivos (Liabilities) Pasivos (Liabilities) Pasivos (Liabilities) Pasivos (Liabilities) Pasivos (Liabilities)
(NAIC Code) ( Domestics Insurers)     (Aggregate Reserve for Life Contracts) (Reserve for Life Contract Claims) (Aggregate Reserve for Accident and Health Contract Claims) (Reserve for Accident and Health Contracts Claims) (Other Liabilities)** (Total Liabilities)