js 取得table中的td值...
时间:2010-08-19 来源:ksqqxq
脑袋不行了,记不住了,记录在案吧,呵呵!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>js遍历table中td的值</title>
<script language="javascript">
function tt(){
var table1=document.getElementById('table1');
var rows=table1.rows;
alert(rows.length);
for(var i=0;i<rows.length;i++){
var uu = rows[i].cells.length;
for(var j = 0 ;j<uu;j++){
alert(rows[i].cells[j].innerHTML);
}
}
}
</script>
</head>
<body>
<table id="table1" width="357" height="196" border="1">
<tr >
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
</table>
<a href="javascript:tt();">BEA 01</a><br />
</body>
</html>
为了兼容,不要使用innerText。。。