How JS and jquery iterate through the contents of table all cells _javascript tips

Source: Internet
Author: User

This example describes the way JS and jquery iterate through the contents of all of the table's cells. Share to everyone for your reference, specific as follows:

Use JS to traverse the table of all the contents of the cell, you can use the following JS code to achieve:

function Getinfofromtable (tableid) {
 var tableinfo = "";
 var tableobj = document.getElementById (tableid);
 for (var i = 0; i < tableObj.rows.length; i++) {//Traverse table for all row for
  (var j = 0; J < Tableobj.rows[i].cells.leng Th J + +) {//Traverse each column in row
   tableinfo + = Tableobj.rows[i].cells[j].innertext;//Get the contents of the cell in the table
   Tableinfo + = "";
  }
  tableinfo + = "\ n";
 }
 return tableinfo;
}

The parameter of this method is the ID that uniquely identifies the table, obtained by using the Document object

JQuery traverses the contents of the TD in TR in table:

1. $ ("#trID TD"). Text () Gets a so the value of TD in Trid returns a string.

2. $ ("#trID"). Children gets a trid under all TD, and then traverses $ ("#trID"). Children use. EQ (index). Text () to get the value in TD;

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">  

I hope this article will help you with your JavaScript programming.

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.