javascript - 隐藏嵌套的 html 表格列

标签 javascript jquery html

我有一个嵌套表列,例如:

enter image description here

现在我想按表列索引隐藏标记列。这怎么可能?请提供概念而不是解决方案。我很困惑如何开始我的任务。

<table class="table table-striped table-bordered table-hover">
  <thead>
    <tr>
      <th style="width: 20%;">Customer Name</th>
      <th style="width: 20%;">Location</th>
      <th style="width: 40%;">
        <table class="table table-striped table-bordered table-hover">
          <thead>
            <tr>
              <th style="width: 50%;">Order No</th>
              <th style="width: 50%;">Date</th>
            </tr>
          </thead>
        </table>
      </th>
      <th style="width: 20%;">No Of Order</th>
    </tr>
  </thead>
  <tbody>
    <tr data-ng-repeat="cutomer in gridData">
      <td style="width: 20%;">{{ cutomer.itemName }}</td>
      <td style="width: 20%;">{{ cutomer.itemName }}</td>
      <td style="width: 40%;">
        <table class="table table-striped table-bordered table-hover">
          <tbody>
            <tr data-ng-repeat="customerOrder in cutomer.orderList">
              <th style="width: 50%;">{{ customerOrder.orderNo }}</th>
              <th style="width: 50%;">{{ customerOrder.date }}</th>
            </tr>
          </tbody>
        </table>
      </td>
      <td style="width: 20%;">No Of Order</td>
    </tr>
  </tbody>
</table>

最佳答案

试试这个:

function show_hide_column(col_no, do_show) {
   var tbl = document.getElementById('id_of_table');
   var col = tbl.getElementsByTagName('col')[col_no];
   if (col) {
     col.style.visibility=do_show?"":"collapse";
   }
}

关于javascript - 隐藏嵌套的 html 表格列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27794721/

相关文章:

jquery - 使用查询将 HTML div 设置为可见

javascript - 带有内联样式的 vendor 前缀

javascript - 多个视频的播放/暂停功能

php - 使用 PHP 将 MySQL 和 Postgres 数据库中的数据放入单个 HTML 表中

java - vaadin 的 Invient 图表最大数据大小

当用户未从下拉列表中选择选项时,jQuery ui 自动完成

html - 如何将内容放在位置绝对元素下方

javascript - 少任务未找到错误

javascript - 在我的代码中添加这个包装器是什么?

javascript - 使用复选框或单选按钮在表单操作之间切换