$(document).ready(function () {
//Get the first tr
var firstRow = $('.header');
//Clone the first row
firstRow.clone().attr('class', 'fixedHeader').prependTo('#ResultsTable');
firstRow.find('th').each(function (i) {
alert(i); //displays 0, 1, 2, 3, 4, 5, 6 (6th is the hidden column that I would like to not calculate)
var thWidth = $(this).width();
$('.fixedHeader th').eq(i).css({
width: thWidth
});
});
});
我正在尝试克隆表格中没有最后一列的第一行。我使用对用户隐藏的 CSS 类 gLine
隐藏最后一列。
上面的脚本仍然采用隐藏列并计算导致克隆标题与表的其余部分不匹配的宽度:
HTML 源是:
如您所见,我只想从 Show Guideline
到 Summary
列,而不计算最后一列,但我的代码也在计算最后一列。
我怎样才能不获取最后一列,以便克隆的标题列与表格列相匹配。
fiddle :http://jsfiddle.net/dmffgowf/ (如您所见,有 7 个警报,这意味着它正在计算最后一列的宽度,这会使所有其他列变小)
最佳答案
试试这个:
firstRow.find('th:not(:last-child)')
不仅仅是
firstRow.find('th')
关于jquery - 如何克隆表格标题行中除最后一列之外的每一列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28434266/