Detailed explanation of example code for traversing cell content with js and jquery

伊谢尔伦
Release: 2017-07-22 09:20:09
Original
1398 people have browsed it

UseJS to traverse the contents of all cells in the Table. You can use the following JS code to achieve this:


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

The parameter of this method is the id that uniquely identifies the Table, which is obtained by using the document object.

jQuery traverses the contents of td in tr in Table:

1. $("#trID td").text() gets a string, so the value of td in trID returns a string.

2. $("#trID").children gets all td under a trID, then traverses $("#trID").children and uses .eq(index).text() to get the td in Value;


    无标题文档   $(document).ready(function() { $("#table a").each(function (){ this.onclick = function(){ var thisObj = this.parentNode.parentNode; var a = $(thisObj).children(); var arr = new Array(); var laber = $("#xiugai label"); for(var i=0;i 
     id 名字 密码 操作   1 张三 12 删除   2 李四 34 删除   3 王五 56 删除   4 六子 78 删除   

ID:
姓名:
密码:
返回

Copy after login

The above is the detailed content of Detailed explanation of example code for traversing cell content with js and jquery. For more information, please follow other related articles on the PHP Chinese website!

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
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!