我如何隐藏一个列在html表中,它有一个合并的标题
How can I hide a column in html table where it has a merged header
我有一个HTML表,其中有多个列的合并标题。我需要以编程方式隐藏/显示一些列,并保留合并的标题为可见列。以下是我使用的表格样本。如有任何建议,不胜感激。
<table width="100%" border="1">
<thead>
<tr>
<th align="center" field="Applicant" title="Funding Source" colspan="6" id="thi_cf_totalprjcost_2">Header 1</th>
</tr>
<tr>
<th width="10%" align="center">Col1</th>
<th width="10%" align="center">Col2</th>
<th width="10%" align="center">Col3</th>
<th width="10%" align="center">Col4</th>
<th width="10%" align="center">Col5</th>
<th width="10%" align="center">Col6</th>
</tr>
</thead>
<tbody>
<tr>
<td>Cell 1-1</td>
<td>Cell 1-2</td>
<td>Cell 1-3</td>
<td>Cell 1-4</td>
<td>Cell 1-5</td>
<td>Cell 1-6</td>
</tr>
<tr>
<td>Cell 2-1</td>
<td>Cell 2-2</td>
<td>Cell 2-3</td>
<td>Cell 2-4</td>
<td>Cell 2-5</td>
<td>Cell 2-6</td>
</tr>
<tr>
<td>Cell 3-1</td>
<td>Cell 3-2</td>
<td>Cell 3-3</td>
<td>Cell 3-4</td>
<td>Cell 3-5</td>
<td>Cell 3-6</td>
</tr>
</tbody>
</table>
如果你提前知道你想隐藏的列,你可以创建CSS规则来方便隐藏,然后应用适当的类到你的表
table.hidesome thead tr:nth-child(2) th:nth-child(3) { display: none; }
table.hidesome tbody tr td:nth-child(3) { display: none; }
<table class="hidesome" width="100%" border="1">
<thead>
<tr>
<th align="center" field="Applicant" title="Funding Source" colspan="6" id="thi_cf_totalprjcost_2">Header 1</th>
</tr>
<tr>
<th width="10%" align="center">Col1</th>
<th width="10%" align="center">Col2</th>
<th width="10%" align="center">Col3</th>
<th width="10%" align="center">Col4</th>
<th width="10%" align="center">Col5</th>
<th width="10%" align="center">Col6</th>
</tr>
</thead>
<tbody>
<tr>
<td>Cell 1-1</td>
<td>Cell 1-2</td>
<td>Cell 1-3</td>
<td>Cell 1-4</td>
<td>Cell 1-5</td>
<td>Cell 1-6</td>
</tr>
<tr>
<td>Cell 2-1</td>
<td>Cell 2-2</td>
<td>Cell 2-3</td>
<td>Cell 2-4</td>
<td>Cell 2-5</td>
<td>Cell 2-6</td>
</tr>
<tr>
<td>Cell 3-1</td>
<td>Cell 3-2</td>
<td>Cell 3-3</td>
<td>Cell 3-4</td>
<td>Cell 3-5</td>
<td>Cell 3-6</td>
</tr>
</tbody>
</table>
相关文章:
- 将行添加到具有固定标题的HTML表中
- 如何使用Javascript在HTML表中查找第一个空行
- 需要将单元格值复制到html表中的其他单元格中
- 如何在html表中插入多个相同的图像
- 从html表中的输入数据创建图表
- Javascript在HTML表中输出在线用户名
- 如何使用 Backbone 将多条记录呈现到 html 表中.js .
- 通过javascript/jquery从html表中获取值并进行计算
- jQuery对象从html表中查询为两个一维数组,用于Chartist图表
- 在HTML表中插入时立即触发操作
- 如何使用javascript在html表中删除字符串
- 如何使用JavaScript检查HTML表中插入的值的类型
- 使用'从HTML表中提取行的内容<tr onclick=alertContents()>'
- 使用regex从巨大的html表中查找某些td值
- 计数HTML表中筛选的结果
- 如何在单击行时获取html表中第一列的值
- 如何比较单元格值和隐藏 html 表中的行
- 从 html 表中选择一行(突出显示)并在单击按钮时发送值
- 当输入字段位于 HTML 表中且其类型为“隐藏”时进行表单验证
- 如何在动态生成的 HTML 表中使用 2D 数组在 TD 标签中设置值