<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<table id="students" width="200" border="1">
<thead >
<tr> <td>学号</td> <td>姓名</td> <td>年龄</td> </tr>
</thead>
<tbody>
<tr> <td>1001</td> <td>张三</td> <td>20</td> </tr>
<tr> <td>1002</td> <td>李四</td> <td>21</td> </tr>
<tr> <td>1003</td> <td>王五</td> <td>19</td> </tr>
<tr> <td>1004</td> <td>赵六</td> <td>20</td> </tr>
</tbody>
</table>
</head>
<body>
</body>
<script>
var mytable = document.getElementById("students");
var nodes = mytable.childNodes;
for(var i = 0;i<nodes.length;i++){
if(nodes[i].nodeName.toUpperCase()=='TBODY'){
var trs = nodes[i].childNodes;
for(var j = 0;j<trs.length;j++){
if(trs[j].nodeName!='text'){
var tds = trs[j].childNodes;
for(var k = 0;k<tds.length;k++){
if(tds[k].nodeName!='#text'){
alert(tds[k].innerHTML);
}
}
}
}
}
}
</script>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<table id="students" width="200" border="1">
<thead >
<tr> <td>学号</td> <td>姓名</td> <td>年龄</td> </tr>
</thead>
<tbody>
<tr> <td>1001</td> <td>张三</td> <td>20</td> </tr>
<tr> <td>1002</td> <td>李四</td> <td>21</td> </tr>
<tr> <td>1003</td> <td>王五</td> <td>19</td> </tr>
<tr> <td>1004</td> <td>赵六</td> <td>20</td> </tr>
</tbody>
</table>
</head>
<body>
</body>
<script>
var mytable = document.getElementById("students");
var nodes = mytable.childNodes;
for(var i = 0;i<nodes.length;i++){
if(nodes[i].nodeName.toUpperCase()=='TBODY'){
var trs = nodes[i].childNodes;
for(var j = 0;j<trs.length;j++){
if(trs[j].nodeName!='text'){
var tds = trs[j].childNodes;
for(var k = 0;k<tds.length;k++){
if(tds[k].nodeName!='#text'){
alert(tds[k].innerHTML);
}
}
}
}
}
}
</script>
</html>