簡體   English   中英

單擊按鈕時如何顯示隱藏的列

[英]How to show hidden column when button is clicked

我有一張桌子,單擊標題時,我需要隱藏/顯示表格列,然后顯示隱藏的列和按鈕。單擊按鈕時,我要顯示隱藏的列我該怎么辦? 在這里查看我的代碼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();
});

演示版

這是一種很不錯的方法 ,您可以繼續隱藏列,並按最近單擊的項目的順序將其移回

基本上添加一個數組來存儲您單擊的列的索引值:

var indexVal = [];

然后在按鈕單擊功能上編寫:

var cells = $('table tr > :nth-child(' + indexVal[indexVal.length-1] + ')');
cells.toggleClass('hide');
indexVal.pop();
if (!indexVal) $('.btnAssociate').hide();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM