js遍历table 和 jquery 遍历table
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">先看看js原生的</span>
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; }
$("table").find("tr").each(function(){ $(this).find("td").each(function(){ alert($(this).text()); }); });