Merge table First column

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.