首页 > 技术文章 > jQuery遍历table

leon719 2014-08-29 12:06 原文

1、

$("table").find("tr").each(function(){
  $(this).find("td").each(function(){
  alert($(this).text());
  });
});

 

2

var tab = document.getElementById("table1");  //找到这个表格
var rows = tab.rows; //取得这个table下的所有行
for(var i=0;i<rows.length;i++)
{
for(var j=0;j<rows[i].cells.length;j++)
{
var cell = rows[i].cells[j];
alert("第"+(i+1)+"行第"+(j+1)+"格的数字是"+cell.innerHTML);
}
}

推荐阅读