Demand
Restores the table containing rowspan and colspan.
For example, the original table is:
The table after the restore is:
Code principles
The table is traversed, if the TD's RowSpan property value is greater than 1, then to the current TD's parent element of the sibling add TD, if the TD's Colspan property value is greater than 1, then the current TD element after adding TD
Copy Code code as follows:
This article starts Blog Park: http://artwl.cnblogs.com (2012/02/08) jquery.fn.reverttable=function () {
$ ("tr", this). each (function (Trindex,tritem) {
$ (Tritem). Find ("TD"). each (function (Tdindex,tditem) {
var rowspancount=$ (Tditem). attr ("rowspan");
var colspancount=$ (Tditem). attr ("colspan");
var value=$ (Tditem). text ();
var newtd= "<td>" +value+ "</td>";
if (rowspancount>1) {
var parent=$ (Tditem). Parent ("tr") [0];
while (rowspancount-->1) {
$ (parent). Next (). prepend (NEWTD);
parent=$ (parent). Next ();
}
$ (Tditem). attr ("rowspan", 1);
}
if (colspancount>1) {
while (colspancount-->1) {
$ (Tditem). After (NEWTD);
}
$ (Tditem). attr ("colspan", 1);
}
});
});
}
Online Demo http://demo.jb51.net/js/2012/jquery_demo/jquery_rowspan_colspan_table.html
Summary
This article provides only one of the options for restoring a table containing rowspan, colspan, and you are welcome to test the discussion.
As for the Merge table cell Web already has code:
Original title: JQuery colspan and rowspan table using cell break
Original address: http://willifirulais.blogspot.com/2007/07/jquery-table-column-break.html