<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www./TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www./1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>無標(biāo)題文檔 </title> </head> <body> <table width="100%" border="1" cellspacing="0" cellpadding="0" id="tab"> <tr> <td>張三 </td> <td>男 </td> <td>22 </td> <td>數(shù)學(xué) </td> <td>90 </td> </tr> <tr> <td>張三 </td> <td>男 </td> <td>22 </td> <td>語文 </td> <td>70 </td> </tr> <tr> <td>張三 </td> <td>男 </td> <td>22 </td> <td>英語 </td> <td>60 </td> </tr> <tr> <td>李四 </td> <td>女 </td> <td>19 </td> <td>數(shù)學(xué) </td> <td>60 </td> </tr> <tr> <td>李四 </td> <td>女 </td> <td>19 </td> <td>語文 </td> <td>60 </td> </tr> <tr> <td>王五 </td> <td>男 </td> <td>19 </td> <td>英語 </td> <td>60 </td> </tr> </table> <script type="text/javascript"> window.onload = function(){ var tab = document.getElementById("tab"); var name, sex, age, count, start; name = sex = age = ""; count = 1; for(var i=0; i<tab.rows.length; i++){ if(name == tab.rows[i].cells[0].innerHTML && sex == tab.rows[i].cells[1].innerHTML && age == tab.rows[i].cells[2].innerHTML){ count++; }else{ if(count > 1){ //合并 start = i - count; tab.rows[start].cells[0].rowSpan = tab.rows[start].cells[1].rowSpan = tab.rows[start].cells[2].rowSpan = count; for(var j=start+1; j<i; j++){ for(var k=0; k<3; k++){ tab.rows[j].removeChild(tab.rows[j].cells[0]); } } count = 1; } name = tab.rows[i].cells[0].innerHTML; sex = tab.rows[i].cells[1].innerHTML; age = tab.rows[i].cells[2].innerHTML; } } }; </script> </body> </html> |
|