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; }
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:
姓名:
密码:
返回