Nik*_*hil 7 html javascript dom html-table
在我的页面中,我有3个表元素,我想使用其标记名访问第3个元素.
所以,我用过 document.getElementByTagName("table")[2];
后来,我尝试通过获取该表中元素的值 table.children[0].children[1].children[2].innerHTML;
然后,我尝试修改已存在的<p>
元素 id="ID"
.
但我没有修改价值?
我的剧本怎么了?
<!DOCTYPE HTML>
<html>
<body>
ID : <p id="ID"></p>
<body>
<table>
</table>
<table>
</table>
<table>
<tbody>
<tr>
</tr>
<tr>
<td>Name</td>
<td>Class</td>
<td>25</td>
</tr>
<tr>
</tr>
</tbody>
</table>
<script>
var table = document.getElementByTagName("table")[2];
var id = table.children[0].children[1].children[2].innerHTML;
document.getElementById("ID").innerHTML = id;
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)