Home > Web Front-end > JS Tutorial > body text

JS使用for循环遍历Table的所有单元格内容_javascript技巧

WBOY
Release: 2016-05-16 16:39:07
Original
1906 people have browsed it

JS遍历Table的所有单元格内容思路是遍历Table的所有Row,遍历Row中的每一列,获取Table中单元格的内容

function GetInfoFromTable(tableid) {
  var tableInfo = "";
  var tableObj = document.getElementById(tableid);
  for (var i = 0; i < tableObj.rows.length; i++) {  //遍历Table的所有Row
    for (var j = 0; j < tableObj.rows[i].cells.length; j++) {  //遍历Row中的每一列
      tableInfo += tableObj.rows[i].cells[j].innerText;  //获取Table中单元格的内容
      tableInfo += "  ";
    }
    tableInfo += "\n";
  }
  return tableInfo;
}
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!