CSDN博客

img ghostzp

访问表格的每个TD

发表于2004/11/3 12:44:00  726人阅读

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
    <title>访问每个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>

阅读全文
0 0

相关文章推荐

img
取 消
img