MERGE table cells in js (the number of rows and columns is unknown during table Partitioning)

Source: Internet
Author: User

MERGE table cells in js (the number of rows and columns is unknown during table Partitioning)

Sys. Application. add_load (function () {var tab = document. getElementById ("ctl00_ContentPlaceHolder1_viewcontrolTT_Repeater1_ctl00_viewcontrolTT_grid"); // The tableID if (! Tab) {alert ("table not obtained! ");} Else {// from the second row, exclude the title line var startRow = 1; // record the contents of td in the table cyclically, used to determine whether the value in td has changed var td1TempV = ""; var td2TempV = ""; var td3TempV = ""; // if the value of td is the same, add 1 to the variable, otherwise, add the temporary variable to the set var rowCount1 = 1; var rowCount2 = 1; var rowCount3 = 1; // obtain the set www.bkjia.com var totalcount1 = new Array () with the same content (); var totalcount2 = new Array (); var totalcount3 = new Array (); for (var I = 1; I <tab. rows. length; I ++) {// take out t first Value of d: var td1Text = tab. rows [I]. cells [0]. innerText; var td2Text = tab. rows [I]. cells [1]. innerText; var td3Text = tab. rows [I]. cells [2]. innerText; // if this is the first cycle, directly continue; if (I = startRow) {td1TempV = td1Text; td2TempV = td2Text; td3TempV = td3Text; continue ;} // if the current value is the same as the source value, add 1 to the temporary quantity; otherwise, add it to the set if (td1TempV = td1Text & td1Text! = Null & td1Text! = "") {RowCount1 ++;} else {totalcount1.push (rowCount1); td1TempV = td1Text; rowCount1 = 1;} if (td2TempV = td2Text & td2Text! = Null & td2Text! = "") {RowCount2 ++;} else {totalcount2.push (rowCount2); td2TempV = td2Text; rowCount2 = 1;} if (td3TempV = td3Text & td3Text! = Null & td3Text! = "") {RowCount3 ++;} else {totalcount3.push (rowCount3); td3TempV = td3Text; rowCount3 = 1;} // determines whether it is the last cycle, if it is the last time that the current quantity is directly stored in the set if (I = tab. rows. length-1) {totalcount1.push (rowCount1); totalcount2.push (rowCount2); totalcount3.push (rowCount3);} // temporary variable, judge whether it is the same as a value in the array during recycling var tNum1 = 0; var tNum2 = 0; var tNum3 = 0; // note that this loop is inverted for (var I = tab. rows. length-1; I> = startRow; I --) {// temporary variable, store td var tTd1 = tab. rows [I]. cells [0]; var tTd2 = tab. rows [I]. cells [1]; var tTd3 = tab. rows [I]. cells [2]; tNum1 ++; tNum2 ++; tNum3 ++; if (tab. rows. length = 2) {continue;} // If the tNum is the same as the last value in the array, then we can conclude that the same td has ended [only one of them] if (tNum1 = totalcount1 [totalcount1.length-1]) {// Add the rowSpan attribute tTd1.setAttribute ("rowSpan", totalcount1 [totalcount1.length-1]) to the current td; tTd1.setAttribute ("style", "background-color: # ffffff "); // bring totalcount1.pop (); tNum1 = 0;} else {// Delete the current td tab. rows [I]. removeChild (tTd1);} if (tNum2 = totalcount2 [totalcount2.length-1]) {// Add the rowSpan attribute tTd2.setAttribute ("rowSpan ", totalcount2 [totalcount2.length-1]); tTd2.setAttribute ("style", "background-color: # ffffff"); // bring totalcount2.pop () to the last element of the array (); tNum2 = 0;} else {// Delete the current td tab. rows [I]. removeChild (tTd2);} if (tNum3 = totalcount3 [totalcount3.length-1]) {// Add the rowSpan attribute tTd3.setAttribute ("rowSpan ", totalcount3 [totalcount3.length-1]); tTd3.setAttribute ("style", "background-color: # ffffff"); // bring totalcount3.pop () to the last element of the array (); tNum3 = 0;} else {// Delete the current td tab. rows [I]. removeChild (tTd3 );}}}});

Related Article

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.