[英]Hide a column in a javascript populated table
I would like to hide the entire age column on this table. 我想在此表上隐藏整个年龄列。
<table id="displayTable">
<tr>
<td class="Name"></td>
<td class="Phone"></td>
<td class="Age"></td>
</tr>
</table>
Javascript follows to hide Age cell - Javascript跟随隐藏年龄细胞-
var table = document.getElementById('displayTable');
var tableRow = table.getElementsByTagName('tr');
for (var row = 0; row < tableRow.length; row++) {
var cells = tableRow[row].getElementsByTagName('td')
cells[2].style.display='none';
}
error says - 错误说-
"2.style is null or not an object." “ 2.style为null或不是对象。”
What am I missing? 我想念什么?
Well, first of all, check your table id. 好吧,首先,检查您的表ID。 You have it set to 'displayTable' but you're attempting to look it up by 'displayLossTable'.
您已将其设置为“ displayTable”,但尝试通过“ displayLossTable”进行查找。
When i fix that id, and plug your code into jsFiddle, everything works. 当我修复该ID并将您的代码插入jsFiddle时,一切正常。
what does alert(cells[2])
give you? alert(cells[2])
给您什么? Alternatively you should try add/remove class instead of inline styles: 另外,您应该尝试添加/删除类而不是内联样式:
el.className+= 'hide'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.