【发布时间】:2014-11-02 22:29:04
【问题描述】:
我通过复制 tr html 然后复制 th 宽度来克隆表标题行。但这失败了,因为当边框:'Wpx' 和边框折叠:'collapse' 时,宽度被写为(宽度减去 W)像素。如果没有设置border-collapse,则宽度写入正确。
代码很简单:
var arr = [];
// copy html, where abc is the destination <tr> and def is the source
$abc.html($def.html());
// now copy widths of table header cells
$def.children().each(function() {arr.push($(this).css("width"));});
$abc.children().each(function(index) {$(this).css("width", arr[index]);});
Fiddle 显示问题:http://jsfiddle.net/marvmartian/9z24j7vz/4/
一种解决方法(在小提琴中说明,但已注释掉)是检查最终表格的大小,如果它们不相等,(hacky)在编写它们之前将 W 添加到宽度。
这种行为似乎是一个错误(使用 Chrome)。显然这是一个特点。我在这里错过了什么?
【问题讨论】:
-
我看不到问题,实际上,在 Firefox 中,但我在 chrome 中看到它......(win7,最新版本的浏览器)
-
脑抽筋,我在 FF 中也看不到。对不起。
标签: javascript jquery css