我只想在表格加载后获取表格列宽,这样我就可以删除列中多余的空格并使其看起来紧凑。我想要的所有表格单元格应该只占用包含它的数据所需的宽度。
表结构是这样的:
<table style="display: table;">
<tbody>
<tr>
<td></td>
<th>word</th>
<th>%</th>
</tr>
<tr>
<th>word</th>
<td><span class="count" style="display:block"> 1</span></td>
<td><span class="percentage" style="display: block;"> 2.6%</span></td>
</tr>
<tr>
<th>word - word word word</th>
<td><span class="count" style="display:block"> 1</span></td>
<td><span class="percentage" style="display: block;"> 2.6%</span></td>
</tr>
<tr>
<th>word - word word word word word</th>
<td> 1</span></td>
<td><span class="percentage" style="display: block;"> 2.6%</span></td>
</tr>
<tr>
<th>word - word word</th>
<td> 2</span></td>
<td><span class="percentage" style="display: block;"> 5.1%</span></td>
</tr>
<tr>
<th>word - word word word</th>
<td><span class="count" style="display:block"> 1</span></td>
<td><span class="percentage" style="display: block;"> 2.6%</span></td>
</tr>
<tr>
<th>word - word word word word</th>
<td><span class="count" style="display:block"> 1</span></td>
<td><span class="percentage" style="display: block;"> 2.6%</span></td>
</tr>
<tr>
<th>word - word word word</th>
<td><span class="count" style="display:block"> 2</span></td>
<td><span class="percentage" style="display: block;"> 5.1%</span></td>
</tr>
<tr>
<th>word - word word</th>
<td><span class="count" style="display:block"> 3</span></td>
<td><span class="percentage" style="display: block;"> 7.7%</span></td>
</tr>
<tr>
<th>word - word word</th>
<td><span class="count" style="display:block"> 25</span></td>
<td><span class="percentage" style="display: block;"> 64.1%</span></td>
</tr>
<tr>
<th>word</th>
<td> 2</span></td>
<td><span class="percentage" style="display: block;"> 5.1%</span></td>
</tr>
</tbody>
</table>