/** * Desc: Merges the adjacent cells of the specified table (table ID table_id) to specify the same text for the column (number of columns table_colnum) * @table_id table ID: The ID of the table that needs to be merged cells. If you specify the table id= "data" in HTML, this parameter should be #data * @table_colnum: The column in which you want to merge the cells. Refer to the Nth-child parameter in jquery. If the number is, the first column on the leftmost list starts at 1; Even "denotes an even sequence;" Odd "denotes odd series; The number of columns represented by "3n+1" is 1, 4, 7 、...... * @table_minrow? : Optional, which represents the column with the lowest number of rows to merge columns, omitting the start of line No. 0 (closed interval) * @table_maxrow? : Optional, which represents the column with the largest number of rows to merge columns, omitting the maximum row count for the last row of the table (open interval) */function Table_rowspan (table_id, Table_colnum) {if (Table_colnum = = "even ") {table_colnum =" 2n "; } else if (Table_colnum = = "Odd") {Table_colnum = "2n+1"; } else {table_colnum = "" + table_colnum; } var cols = []; var all_row_num = $ (table_id + "tr td:nth-child (1)"). Length; var all_col_num = $ (table_id + "tr:nth-child (1)"). Children (). length; if (Table_colnum.indexof ("n") = =-1) {cols[0] = Table_colnum; } else {var n = 0; var a = table_colnum.substring (0, Table_colnum.indexof ("n")); var B = table_colnum.substring (table_colNum.indexof ("n") + 1); A = a? parseint (a): 1; b = b? parseint (b): 0; while (A * n + b <= all_col_num) {Cols[n] = a * n + b; n++; }} var table_minrow = arguments[2]? ARGUMENTS[2]: 0; var table_maxrow = arguments[3]? ARGUMENTS[3]: All_row_num + 1; var table_firsttd = ""; var table_currenttd = ""; var table_spannum = 0; for (var j = 0; J < Cols.length; J + +) {$ (table_id + "tr td:nth-child (" + cols[j] + ")"). Slice (Table_minrow, TA Ble_maxrow). Each (function (i) {var table_col_obj = $ (this); if (table_col_obj.html () = "") {if (i = = 0) {TABLE_FIRSTTD = $ (this); Table_spannum = 1; } else {Table_currenttd = $ (this); if (table_firsttd.text () = = Table_currenttd.text ()) {table_spannum++; Table_currenttd.hide (); //remove (); Table_firsttd.attr ("RowSpan", table_spannum); } else {Table_firsttd = $ (this); Table_spannum = 1; } } } }); }}/** * Desc: Merges the adjacent cells of the specified table (table ID table_id) to specify the same text for the row (the number of rows is table_rownum) * @table_id table ID: is the ID of the table that needs to be merged cells. If you specify the table id= "data" in HTML, this parameter should be #data * @table_rownum: The row where you want to merge the cells. Refer to the Nth-child parameter in jquery. If the number is the first column from the leftmost 1, start with Even "means even rows;" Odd "denotes odd rows; The number of rows represented by "3n+1" is 1, 4, 7 、...... * @table_mincolnum? : Optional, which represents the smallest column in the row to be merged, omitting the beginning of the No. 0 column (closed interval) * @table_maxcolnum? : Optional, which represents the largest column in the row to merge, omitting the maximum number of columns (open interval) for the table */function Table_colspan (table_id, table_rownum) {var table_mincolnum = arguments[2 ] ? ARGUMENTS[2]: 0; var table_maxcolnum; var table_firsttd = ""; var table_currenttd = ""; var table_spannum = 0; $ (table_id + "tr:nth-child (" + Table_rownum + ")"). each (function (i) {table_row_obj = $ (this). Children (); Table_maxcolnum = ArgumENTS[3]? ARGUMENTS[3]: table_row_obj.length; Table_row_obj.slice (Table_mincolnum, Table_maxcolnum). Each (function (i) {if (i = = 0) {Table_fi RSTTD = $ (this); Table_spannum = 1; } else if ((Table_maxcolnum > 0) && (i > Table_maxcolnum)) {return ""; } else {Table_currenttd = $ (this); if (table_firsttd.text () = = Table_currenttd.text ()) {table_spannum++; if (table_currenttd.is (": Visible")) {Table_firsttd.width (parseint (Table_firsttd.width ()) + Parsein T (Table_currenttd.width ())); } table_currenttd.hide (); Remove (); Table_firsttd.attr ("ColSpan", table_spannum); } else {Table_firsttd = $ (this); Table_spannum = 1; } } }); });} Call: Represents the first column of a table with ID RECORDTB, the same content merges Table_rowspan ("#recordTb", 1);
This chapter quotes: http://www.jb51.net/article/81977.htm
jquery implements the merging of HTML table cells (merging rows or columns with the same content)