2014-04-06 35 views
0

我正在处理目前第一列应该使用jquery动态删除的表格。在移除第一栏后,tr高度根据内容自行调整。删除第一列后保留表格'tr'的高度

我想tr高度是相同的,即使删除第一个col。请提出答案。

这是我用来去除第一关口

$(document).ready(function(){ 
    $('.remove tr').each(function(){ 
    $(this).find('td:first-child').remove(); 
    $(this).find('th:first-child').remove(); 
    }) 
}) 

请参阅本Fiddle

+0

检索TR高度和拆卸电池之前,经由.CSS应用它。由于表格收缩/扩展到其内容,tr高度将作为最小高度。 –

回答

1

添加的line-height代码:0像素,在你的CSS宽度和高度类似以下内容:

td,th{ 
    border:1px solid #ccc; 
    line-height:0px; 
    height:40px; 
    width:100px; 
    } 

看到这个更新的小提琴:Demo 希望这会有所帮助。

+0

看到这个更新小提琴:http://jsfiddle.net/zWCz8/2/ –

+0

作为一个很好的做法你应该张贴在ANS –

+0

演示链接,这是不给确切height.thanks –

0

你可以在css中添加你的tr固定高度,或者如果你想在删除col之前检查你的表格行的高度,然后设置固定的高度。

删除之前:

var trHeight = $('tr').height(); 

,然后添加新的高度删除山坳后:

$('tr').css('height', trHeight+'px'); 

编辑:你可以用“日”或任何类别的更换“TR”想要

0

我认为你应该在删除它之前捕获你的tr高度。于是,我尝试了一下在你的jsfiddle和它的工作对我来说,如果我改变了这种

$(document).ready(function(){ 
    $('.remove tr').each(function(){ 
    $(this).find('td:first-child').remove(); 
    $(this).find('th:first-child').remove(); 
    }) 
}) 

$(document).ready(function(){ 
    var tr_height = $('.remove tr').height(); 
    $('.remove tr').each(function(){ 
     $(this).find('td:first-child').remove(); 
     $(this).find('th:first-child').remove();  
    }) 
    $('td:first-child, th:first-child').css('height', tr_height); 
}) 

当然,你可以选择捕捉td在单独的js变量高度和th

+0

这仅仅反映了第一个tr –

0

找到答案在一些敏感表设计

var cloned = $('.remove').clone().addClass('cloned'); 
$('.remove tr').each(function(){ 
$(this).find('td:first-child').remove(); 
$(this).find('th:first-child').remove(); 
}) 
var tr = $('.remove').find('tr'); 
var tr_copy = $('.cloned').find('tr'); 
var heights = []; 
tr.each(function (index) { 
var self = $(this), 
tx = self.find('th, td'); 
tx.each(function() { 
var height = $(this).outerHeight(true); 
heights[index] = heights[index] || 0; 
if (height > heights[index]) heights[index] = height; 
}); 
}); 
tr_copy.each(function (index) {     $(this).height(heights[index]); 
}); 

感谢所有