1

我正在使用 JQuery 数据表最新插件。我有标题和正文列未对齐的问题。我想要做的是我想读取每个标题列的宽度和相应的正文列的宽度,并将最大值设置为 th 和 td。但我无法读取 th 或 td 的宽度属性。我怎样才能做到这一点?

我尝试了以下返回空白

$("myTable thead tr th).each(function(){ var width = $(this).width});
4

1 回答 1

2

您应该在下面使用,替换widthwidth(). $(this)应该调用函数而不是属性。

注意- 您错过了 的结束引号$("myTable thead tr th),请更正它。

$("myTable thead tr th").each(function(){ var width = $(this).width()});

如果要使用属性,请使用this而不是$(this)

$("myTable thead tr th").each(function(){ var width = this.width});
于 2014-09-18T06:10:22.460 回答