Recently, I always met the first column is the city, the second row is county. Said a bunch of counties and cities to a city looks not very good, to the first column of the city to merge together. Therefore wrote a small demo, left for later reuse.
Look first, table one is the original data effect, table two is the data effect after merging the first column:
The core code is a small segment of JS:
<script type= "text/javascript" >window.onload = function () { mergetable ("Tt2", 0,1); }; /* TableId: The Id,mergecolindex of the table: column ordinal to merge, Beginrowindex: The row ordinal of the merge start /function mergetable (Tableid,mergecolindex, Beginrowindex) { var table = document.getElementById (tableId); if (table!=null) { var totalrows = table.rows.length; for (Var i=beginrowindex;i<totalrows;i++) { var rowSpan = 1; var cell = table.rows[i].cells[mergecolindex].innerhtml; for (Var j=i+1;j<totalrows;j++) { if (Table.rows[j].cells[mergecolindex].innerhtml==cell) { rowspan++; Table.rows[i].cells[mergecolindex].rowspan = rowspan;//set RowSpan Table.rows[j].cells[mergecolindex]. Style.display = "none";//The current line is merged, so this is set to none }else{break ; } } i = i+rowspan-1;//jumps to the last identical row, and then +1 is another different row } } }</script>
Here is my static HTML code, can be directly copied down, put into a text file, and then saved as. html file, you can directly open to see the effect.
<! DOCTYPE html>
Merge table First column