js遍历table
js遍历table
var tableObj = document.getElementById("tableName");
var str = "";
for(var i=0;i<tableObj.rows.length;i++)
{
for(varj=0;j<tableObj.rows[i].cells.length;j++)
{
//str += tableObj.rows[i].cells[j].innerHTML+" ";
for(var z=0;z<tableObj.rows[i].cells[j].children.length;z++)
{
var text = tableObj.rows[i].cells[j].children[z];//取得text object
str += text.value;
}
}
str+=""n";
}
alert(str);
var str = "";
for(var i=0;i<tableObj.rows.length;i++)
{
for(varj=0;j<tableObj.rows[i].cells.length;j++)
{
//str += tableObj.rows[i].cells[j].innerHTML+" ";
for(var z=0;z<tableObj.rows[i].cells[j].children.length;z++)
{
var text = tableObj.rows[i].cells[j].children[z];//取得text object
str += text.value;
}
}
str+=""n";
}
alert(str);