我正在尝试克隆表中的一行,并将该行插入到空表中。简单。
但是是否可以保留 tr 中单元格的原始宽度(可能会由于同一列中的其他单元格而扩展)?
编辑刚刚意识到我应该在克隆后迭代匹配的单元格并同步宽度。仍然好奇是否有更直接的方法......
最佳答案
克隆行,然后迭代该行的子行,将每个子行的宽度设置为相应索引处原始行的每个子行。
var target = $('#target');
var target_children = target.children();
var clone = target.clone();
clone.children().width(function(i,val) {
return target_children.eq(i).width();
});
$('<table>',{border:1}).append(clone).appendTo('body');
示例: http://jsfiddle.net/z7hWh/
我不确定浏览器是否支持在<td>
上设置宽度.
关于jquery - 克隆 tr,但保留宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6539489/