【问题标题】:How to: Multiple tables with each row of each table with the same height如何:多个表格,每个表格的每一行具有相同的高度
【发布时间】:2011-11-23 13:29:04
【问题描述】:

我目前在这个 JsFiddle code snippet 3 个表中,中心表名为 .sl_scrollingTable,其他表名为 .sl_NewFixedTable

我想要做的是让所有三张桌子上的每一行都具有相同的高度。它适用于.sl_NewFixedTable 的第一个实例,但不适用于第二个实例。不知道为什么,请帮忙。

【问题讨论】:

  • 你也应该在这里粘贴你的代码。如果有一天 jsfiddle.net 关门了……那么这个问题将变得毫无用处。
  • 操作方法如下:jsfiddle.net/2uux2/2

标签: jquery html-table


【解决方案1】:

您可以使用来自 his blog 的 John Resig 的 Array.minArray.max

我已经更新了你的 jsfiddle:http://jsfiddle.net/2uux2/1/

但是,这是其他人可以查看的代码。

// document onload
Array.max = function( array ){
    return Math.max.apply( Math, array );
};
Array.min = function( array ){
    return Math.min.apply( Math, array );
};

var h= $('tr').map(function() {
        return $(this).height();
}).get();

var maxHeight = Array.max(h);
console.log('Max height: ' + maxHeight );

$('tr').css({height:maxHeight });

【讨论】:

  • 非常感谢您。但是我在萤火虫中收到一条错误消息“Function.prototype.apply 的第二个参数必须是一个数组返回 Math.max.apply(Math, array)”虽然它在 js fiddle 中效果很好我似乎无法让它在我正在处理 html :(
  • 啊,试试Array.max(h.get())从jquery对象中取出数组。
  • 感谢这似乎有效,但它似乎将最大高度应用于所有行而不是每行的最大值,如果这有意义的话。非常感谢您的帮助
  • 你发现了吗?您需要每个表的行高数组,然后按索引合并数组,以便a[0] = [ b[0], c[0], d[0] ]。然后,您将遍历行并将 css 应用于合并数组索引处的值 (a)。
  • 如果写到这里 - $("table").each(function(index, element) { window["element"+index]=$('tr', this). map(function() { return $(this).height(); }).get(); 这会创建数组,但我不知道如何检查彼此的索引
猜你喜欢
  • 1970-01-01
  • 2022-01-19
  • 2015-07-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-03
  • 2013-03-29
  • 1970-01-01
相关资源
最近更新 更多