最近写个GridView,由于不是很熟悉javascript,用jquery实现后,发现下面设置左右表行高的代码如果不把行保存在$tr1,$tr2中再设置css,速度非常慢,300行50列左右的数据得1分钟左右,如下修改后只要7,8秒。各位大大看看能否帮忙分析一下。$fixedTrs固定列的行,$freeTrs非固定列行。function resetRowHeight ($fixedTrs, $freeTrs){var rhs = [], l1 = $fixedTrs.length, l2 = $freeTrs.length, $tr1 = [], $tr2 = [], minheight = parseInt(this.options.minRowHeight, 10) || 0; isNaN(minheight) && (minheight = 0);
for (var i = 0; i < l2; i++) { var tr1, tr2; $tr2[i] = tr2 = $freeTrs.eq(i).css({ "max-height": "", "height": "" }); var rh = Math.max(minheight, tr2.children().height()); if (l1 == l2) { $tr1[i] = tr1 = $fixedTrs.eq(i).css({ "max-height": "", "height": "" }); rh = Math.max(rh, tr1.children().height()); } rhs[i] = rh; } for (var j = 0; j < l2; j++) { var cssArgs = { "max-height": (rhs[j] + 2) + "px", "height": (rhs[j] + 2) + "px" }; if (l1 == l2) { $tr1[j].css(cssArgs); } $tr2[j].css(cssArgs); } }
时间: 2024-10-12 17:20:45