使用 javascript 根据另一个 table 中的行数更改 table 宽度

Change table width based on number of rows in another table using javascript

我的 Html 页面有 2 tables :

css :

.af_column_column-header-table { 
     width = 100% !important;
 }

问题:

您可以在 :first-child 的帮助下使用 querySelectorAll 到 select 第一个 table,然后使用 .style.width 设置样式:

var rows_count = document.querySelectorAll('table.af_column_column-header-table:first-child tr').length;

if( rows_count > 1){
  document.getElementById('Table1').style.width = '99.3%';
}

i have many tables on my page that uses the same style class af_column_column-header-table i want to do that for the first table only.

这将通过使用 :first-child select 或

来实现