我有一个表格,我需要隐藏/显示表格列,当单击标题时,该列隐藏,并且按钮将出现。当单击按钮时,我想显示隐藏的列,我该怎么做? 在这里查看我的代码 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();
});
关于javascript - 单击按钮时如何显示隐藏列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20566726/