我想编写一个 javascript 函数,它在单击按钮时更改 html-th 的名称。我的问题是,我不知道如何获取th
.
document.getElementById("id").text
和
document.getElementById("id").value
不工作。
我想编写一个 javascript 函数,它在单击按钮时更改 html-th 的名称。我的问题是,我不知道如何获取th
.
document.getElementById("id").text
和
document.getElementById("id").value
不工作。
你应该使用innerHTML
HTML:
<table>
<thead>
<tr>
<th id="headId">Col name</th>
</tr>
</thead>
<tbody>
<tr>
<td>Info</td>
</tr>
</tbody>
</table>
<input type="button" value="Click" onclick="getHeadName()" />
JS:
function getHeadName() {
var headName = document.getElementById("headId").innerHTML
}