jquery implements an append table without using the stitching HTML method

Source: Internet
Author: User

The following is my original, reproduced please indicate the source.

/*
* Append rows to the table
*
* @param tableId need to append table ID @param tablerowdata
* Append rows of data (JSON format, need to be discharged in the order of the columns and all already format completed)
*
* @return No
*
*/
function Addtablerow (tableId, Tablerowdata) {
var inserttr = $ (' # ' + tableId + ' Tr:last '). Clone (True);
var Jsonarray = eval ("(" + Tablerowdata + ")");
Set serial number
var tablelength = $ ("#" + tableId). Find ("tr"). Length;
Inserttr.children (' TD '). EQ (0). html (tablelength + 1);
Append the JSON data loop to each column of the table
var i = 1;
for (Var jsonunit in Jsonarray) {
Inserttr.children (' TD '). EQ (i). html (Jsonarray[jsonunit]);
i++;
}
$ (' # ' + tableId + ' Tr:last '). After (inserttr);
}

/*
* Update data for a row in table
*
* @param tableId need to append the ID of table @param rowNum the row number of table should be updated (by default from 1) @param
* Tablerowdata Append rows of data (JSON format, need to be discharged in the order of the columns and all already format completed)
*
* @return No
*
*/
function Upttablerow (tableId, RowNum, Tablerowdata) {
var upttr = $ (' # ' + tableId + ' tr: ' + rowNum);
var Jsonarray = eval ("(" + Tablerowdata + ")");
Append the JSON data loop to each column of the table
var i = 1;
for (Var jsonunit in Jsonarray) {
Upttr.children (' TD '). EQ (i). html (Jsonarray[jsonunit]);
i++;
}
}

jquery implements an append table without using the stitching HTML method

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.