Javascript:计算表格行中的列数 [英] Javascript: Count number of columns in a table row
本文介绍了Javascript:计算表格行中的列数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张类似于
< table id =table1>的表格。
< tr>
< td>< input type =textvalue =/>< / td>
< td>< input type =textvalue =/>< / td>
< td>< input type =textvalue =/>< / td>
< td>< input type =textvalue =/>< / td>
< / tr>
< tr>
< td>< input type =textvalue =/>< / td>
< td>< input type =textvalue =/>< / td>
< td>< input type =textvalue =/>< / td>
< td>< input type =textvalue =/>< / td>
< / tr>
< table>
我想计算一行中td元素的数量。我正在尝试
document.getElementById('')。cells.length;
document.getElementById('')。length;
document.getElementById('')。getElementsByTagName('td')。length;
没有显示实际结果。
解决方案
document.getElementById('table1')。rows [0] .cells.length
pre>
单元格不是表格的属性,行是。虽然>单元格是一行的属性
I have a table similar to
<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>
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;
It did not show actual result.
解决方案document.getElementById('table1').rows[0].cells.length
cells is not a property of a table, rows are. Cells is a property of a row though
这篇关于Javascript:计算表格行中的列数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文