JS访问表格的每行的每个TD的方法

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>网页特效|Linkweb.cn/Js|---访问表格的每个TD</title>
</head>
<script>
function showText(){
  var oTbody=table1.children.item(0);
  for(var i=0;i<oTbody.children.length;i++)
  {
     var oTR=oTbody.children.item(i);
         for(var j=0;j<oTR.children.length;j++)
           text1.value+="第"+(i+1)+"行;"+"第"+(j+1)+"列的内容是:"+oTR.children.item(j).innerHTML+"\n";
  }
}
</script>
<body>
<table border="1" id="table1">
<tr>
<td>safssd</td>
<td>asfdasdf</td>
<td>asfasdfsafsad</td>
</tr>
<tr>
<td>asdfafsda</td>
<td>sdfasfasdsadf</td>
<td>sdfasdfasdfasfd</td>
</tr>
</table>
<button onclick="showText()">showText</button>
<textarea id="text1" rows="10" cols="100"></textarea>
</body>
</html>

posted on 2009-04-16 15:28  念时  阅读(534)  评论(0编辑  收藏  举报

细节决定成败!态度决定一切!