我有下表
<table>
<thead>
<tr>
<th col="value2"></th>
</tr>
</thead>
<tbody>
<tr id="value1">
<td></td>
</tr>
</tbody
<table>
我使用下面的方法从 <tr>
获取“value1”
"row_id": this.parentNode.getAttribute('id')
我正在尝试使用下面的方法从 <th>
获取 col 值但它返回一个空值。
"colName": this.getAttribute('col')
如何正确从 <th>
获取 col 属性值?
最佳答案
尝试这个 dom 函数:
document.getElementsByTagName("th")[0].getAttribute("col");
关于java - 如何从表中获取属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15700170/