The implementation method of a table containing rowspan and colspan is restored through jquery _jquery

Source: Internet
Author: User
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

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.