删除/隐藏表的空列,包括< th> [英] remove/hide table's empty column(s), including <th>

查看:87
本文介绍了删除/隐藏表的空列,包括< th>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何隐藏包含该列中所有空单元格的列,包括标题< th> ,同时保留其他列及其标题。以下jquery隐藏了整个< th> ,这不是我想要的。 这里是一个示例,我想隐藏整个'Column3',包括<的第i; 。非常感谢提前。

How can I hide the column with all empty cells including the title <th> in that column, while leaving the other columns and their titles as it is. Following jquery hides the entire <th>, which is not I want. Here is a sample, where I want to hide only the entire 'Column3' including <th>. Many thanks in advance.

$('table#mytable tr').each(function() {
    if ($(this).children('td:empty').length === $(this).children('td').length) {
        $(this).hide();
    }
});


推荐答案

花了一段时间拼凑起来。感谢一些代码的nxt。

Took a while to piece together. Thanks to nxt for some of the code.

$('#mytable th').each(function(i) {
    var remove = 0;

    var tds = $(this).parents('table').find('tr td:nth-child(' + (i + 1) + ')')
    tds.each(function(j) { if (this.innerHTML == '') remove++; });

    if (remove == ($('#mytable tr').length - 1)) {
        $(this).hide();
        tds.hide();
    }
});

这篇关于删除/隐藏表的空列,包括&lt; th&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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