首页 > 代码库 > 获取table行列

获取table行列

var table =document.getElementById("add_purchaseOrderDetailList_table");
var rows = table.rows.length;
var colums = table.rows[0].cells.length;
for(var i=0;i<rows;i++)
alert(table.rows[i].cells[0].innerHTML);
});

 

--------------------

<!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>无标题文档</title><script type="text/javascript" language="javascript"> function init() {   var table =document.getElementById("tab1");   var rows = table.rows.length;   alert(行数+rows);   var colums = table.rows[0].cells.length;   alert(列数+colums); }</script></head><body onload="init()"><table width="80%" border="1" id="tab1">  <tr>    <td>1</td>    <td>2;</td>    <td>3;</td>    <td>4;</td>  </tr>  <tr>    <td>22;</td>    <td>21;</td>    <td>34;</td>    <td>12;</td>  </tr>   <tr>    <td>12;</td>    <td>21;</td>    <td>45;</td>    <td>65;</td>  </tr></table></body></html>

 

获取table行列