Javascript遍历Html Table示例(包括内容和属性值)
1:遍历并输出Table中值
<tableid="tb">
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
</table>
functionf()
{
vart=document.getElementById("tb").childNodes.item(0);
for(vari=0;i<t.childNodes.length;i++)
{
for(varj=0;j<t.childNodes(i).childNodes.length;j++)
{
alert(t.childNodes(i).childNodes(j).innerText);
}
}
}
2:遍历Table,读取CheckBox状态和其他Column值
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><title>UntitledPage</title></head><bodyonload="f()">
<scripttype="text/javascript">
functionf()
{
vart=document.getElementById("tb").childNodes.item(0);
for(vari=0;i<t.childNodes.length;i++)
{
alert(t.childNodes(i).firstChild.firstChild.nodeValue);
alert(t.childNodes(i).childNodes[1].firstChild.checked);
}
}
</script>
<tableid="tb">
<tr>
<tdstyle="width:122px">
1234</td>
<tdstyle="width:89px">
<inputtype="checkbox"/></td>
<tdstyle="width:210px">
</td>
</tr>
<tr>
<tdstyle="width:122px;height:21px">
2234</td>
<tdstyle="width:89px;height:21px">
<inputtype="checkbox"checked="CHECKED"/></td>
<tdstyle="width:210px;height:21px">
</td>
</tr>
<tr>
<tdstyle="width:122px">
3234</td>
<tdstyle="width:89px">
<inputtype="checkbox"/></td>
<tdstyle="width:210px">
</td>
</tr>
</table>
</body>
</html>热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短