计算表格行中的列数 [英] Count number of columns in a table row

查看:85
本文介绍了计算表格行中的列数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表格类似于:

<table id="table1">
<tr>
  <td><input type="text" value="" /></td>
  <td><input type="text" value="" /></td>
  <td><input type="text" value="" /></td>
  <td><input type="text" value="" /></td>
</tr>
<tr>
  <td><input type="text" value="" /></td>
  <td><input type="text" value="" /></td>
  <td><input type="text" value="" /></td>
  <td><input type="text" value="" /></td>
</tr>
<table>

我想计算一行中td元素的数量。我正在尝试:

I want to count the number of td element in a row. I am trying:

document.getElementById('').cells.length;
document.getElementById('').length;
document.getElementById('').getElementsByTagName('td').length;

它没有显示实际结果。

推荐答案

document.getElementById('table1').rows[0].cells.length

cells不是表的属性,行是。虽然

cells is not a property of a table, rows are. Cells is a property of a row though

这篇关于计算表格行中的列数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆