【问题标题】:Set JQuery DataTable Columns Width manually手动设置 JQuery DataTable Columns Width
【发布时间】:2014-09-18 06:05:28
【问题描述】:
我正在使用 JQuery 数据表最新插件。我有标题和正文列未对齐的问题。我想要做的是我想读取每个标题列的宽度和相应的正文列的宽度,并将最大的两个设置为 th 和 td。但我无法读取 th 或 td 的宽度属性。我该怎么做?
我尝试了以下返回空白的方法
$("myTable thead tr th).each(function(){ var width = $(this).width});
【问题讨论】:
标签:
jquery
datatable
width
manual
dynamic-columns
【解决方案1】:
您应该在下面使用,将width 替换为width()。 $(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});