首页 > 解决方案 > 读取打字稿中的所有表头列名

问题描述

下面是我的表结构。我想阅读打字稿中的所有表格标签或标题列。

<table>
<tr>
<th>name</th>
<th>dob</th>
</tr>
</table>

实际上我的意图是读取所有表头(标签)并想像下面这样应用css类我不想硬编码

document.getElementById("name").className = "defaultSort"; 
document.getElementById("dob").className = "defaultSort"; 

请任何人都可以在这里提供帮助

标签: angulartypescriptangular6typescript2.0

解决方案


https://developer.mozilla.org/nl/docs/Web/API/Document/querySelector

document.querySelectorAll("#uniqueTableName th")

这将获取所有表头元素,对其进行循环以设置不同的类等。


推荐阅读