javascript - 单击按钮时如何显示隐藏列

标签 javascript jquery html button show-hide

我有一个表格,我需要隐藏/显示表格列,当单击标题时,该列隐藏,并且按钮将出现。当单击按钮时,我想显示隐藏的列,我该怎么做? 在这里查看我的代码 http://jsfiddle.net/9QkVd/29/

谢谢

$(function() {
    $('table tbody tr:odd').addClass('alt');

    $('table tbody tr').hover(function() {
        $(this).addClass('hover');
    }, function() {
        $(this).removeClass('hover');
    });
});

$('tr th:gt(0)').click(function() {

    var index = (this.cellIndex + 1);
    var cells = $('table tr > :nth-child(' + index + ')');
    cells.toggleClass('hide');

    if ($(this).hasClass('hide')) {
        $(this).find('span').html('<b>+</b>');
    }
    else {
        $(this).find('span').html('<b>-</b>');
    }

    if ($('table tr > th:not(.hide)').length)
        $('table').removeClass('hide');
    else
        $('table').addClass('hide');
     $('.btnAssociate').show();
});

 $('.btnAssociate').click(function()
    {


         $('.btnAssociate').hide();

    });

最佳答案

试试这个,

$('.btnAssociate').click(function () {
    $('table th,table td').removeClass('hide');
    $('.btnAssociate').hide();
});

Demo

关于javascript - 单击按钮时如何显示隐藏列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20566726/

相关文章:

javascript - Script 或 Style 标签源中的查询参数

jQuery 手机 “Error Loading Page”

javascript - 按索引对 javascript multliarray 进行分组并获得总和和平均值

html - 如何更改disqus文本区域的颜色

javascript - 基于十进制子字符串解析和排序字母数字元素

jquery - Twitter bootstrap 附加无限滚动和 window.resize

javascript - 在本地文件系统上的 html 文件中包含 html 文件?

javascript - 如何在 C# 中清除 javascript SessionStorage

javascript - 如何在reactjs中为数字输入字段设置默认值?

javascript - 为什么我的大部分结果都是 nan