你如何计算<td>特定元素的数量<tr>?
我没有直接指定id或name,我们必须使用这个document.getElementsByTagName概念.
您可以使用以下内容:
var rowIndex = 0; // rowindex, in this case the first row of your table
var table = document.getElementById('mytable'); // table to perform search on
var row = table.getElementsByTagName('tr')[rowIndex];
var cells = row.getElementsByTagName('td');
var cellCount = cells.length;
alert(cellCount); // will return the number of cells in the row
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20182 次 |
| 最近记录: |