给定一个固定头HTML表,我试图排队标题列与正文行列。我这样做是因为我使用CSS来使头部固定,而头部与身体其他部分不一致。设置TH最小和最大宽度非常缓慢
我正在使用的JavaScript工程,但速度非常慢。关于我如何加快速度的任何想法?
下面是显示问题的小提琴。现在,相对较小的桌子需要5秒钟以上。 /w93NU/
这里是我使用的代码:
function fixedHeader($table) {
//This function compares the header row with the first body row and lines up all of the widths
var firstRowTds = $table.children("tbody:first").children("tr:first").children("td");
var headerRowThs = $table.find("th");
for (var i = 0; i < firstRowTds.length; i++) {
var head = headerRowThs[i];
var cell = firstRowTds[i];
var width = (Math.max($(cell).outerWidth(), $(head).outerWidth())) + "px";
//Here are my problem pieces. Setting these values are what kills the perfomanrce
$(cell).css({
"min-width": width,
"max-width": width
});
$(head).css({
"min-width": width,
"max-width": width
});
}
}
+0
请在下面看到我的新答案。 –