在javascript中计算表格宽度的百分比而不是像素

calculate table th width in percentage instead of pixel in javascript

本文关键字:百分比 像素 javascript 计算 表格      更新时间:2023-09-26

如何使用javascript计算表格宽度的百分比并将该宽度分配给表格tbody td ?

 $('#headerwidth').find('thead th').each(function(){
  var rowval = $(this).outerWidth()+'px' ;

您可能需要在thead的current循环中编写一个循环:

 $('#headerwidth').find('thead th').each(function(){
     var rowval = $(this).outerWidth()+'px' ;
     $('#headerwidth').find('tbody tr td').each(function(){
        $(this).css("width", rowval)
     });
});