0

我需要通过更改 CSS 设置/样式来设置动态添加到页面的表格的样式。不知何故,这不起作用,我正在寻找解决这个问题的方法。如何为动态创建的表调整表头和列的大小?

4

2 回答 2

0

查看 jquery .css()

http://api.jquery.com/css/

$("th").css( "width", value )

Jquery 有一些函数可以动态改变 css 属性。还有一些宽度的函数

$("th").width( value )

http://api.jquery.com/width/

将表添加到页面后调用这些函数。

于 2012-04-21T17:06:02.083 回答
0

如果表有 id 或类,您可以直接在 css 中定位它们。如果它们被过度使用,请为它们添加一个 !important 标签。

table#idhere {width:500px !important}

或者

table.clashere {width:500px !important}


这将找到表格的宽度,然后将其添加为属性,以便对其进行设置。

var tableWidth = $('#tbl_reportview table.report').width();
$('#tbl_reportview table.report').attr('width',tableWidth + 'px');
于 2012-04-21T17:21:02.107 回答