我如何获取表格中第一个td元素的宽度和高度?
<div class="page">
<table>
<tr>
<td></td>
...
</tr>
</div>
您可以使用clientHeight和clientWidth-注意在此演示中queryAll选择器仅针对单个td-您将需要扩展该选择器以获取正确的TD。
let tableCell = document.querySelector('td');
let cellWidth = tableCell.clientWidth +'px';
let cellHeight = tableCell.clientHeight +'px';
console.log('width: ' + cellWidth, ' / height: ' + cellHeight);
<div class="page">
<table>
<tr>
<td>Test</td>
</tr>
</table>
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句