解析dom中的children对象数组元素firstChild,lastChild的使用_javascript技巧
来源:动视网
责编:小采
时间:2020-11-27 21:11:53
解析dom中的children对象数组元素firstChild,lastChild的使用_javascript技巧
解析dom中的children对象数组元素firstChild,lastChild的使用_javascript技巧: 代码如下: 行1列1 行1列2 行2列1 行2列2 alert(test.children[0].tagName) alert(test.children[1].tagName) children 代表对象的子节点数组--> document.all.tbl.child
导读解析dom中的children对象数组元素firstChild,lastChild的使用_javascript技巧: 代码如下: 行1列1 行1列2 行2列1 行2列2 alert(test.children[0].tagName) alert(test.children[1].tagName) children 代表对象的子节点数组--> document.all.tbl.child

代码如下:
alert(test.children[0].tagName)
alert(test.children[1].tagName)
script>
children 代表对象的子节点数组-->
document.all.tbl.children(0).children(0).innerHTML解释
document.all.tbl.children(0)定位到table的第一个子节点
document.all.tbl.children(0).children(0)定位到table的第一个子节点的第一个子节点,打印结果| 行1列1 | 行1列2 |
document.all.tbl.children(0).children(1).innerHTML,打印结果
行2列1 | 行2列2 |
document.all.tbl.children(0).children(1).children(0).innerHTML 打印结果行2列2
alert(test.firstChild.tagName)
alert(test.lastChild.tagName)
script>
document.all.tbl.firstChild定位到table的第一个子节点
document.all.tbl.firstChild.firstChild定位到table的第一个子节点
的第一个子节点
document.all.tbl.firstChild.firstChild.innerHTML打印结果是 行1列1 | 行1列2 |
document.all.tbl.firstChild.lastChild定位到table的第一个子节点
的最后子节点
document.all.tbl.firstChild.lastChild.innerHTML打印结果是 行2列1 | 行2列2 |
document.all.tbl.firstChild.lastChild.firstChild.innerHTML 打印结果是
行2列2
解析dom中的children对象数组元素firstChild,lastChild的使用_javascript技巧
解析dom中的children对象数组元素firstChild,lastChild的使用_javascript技巧: 代码如下: 行1列1 行1列2 行2列1 行2列2 alert(test.children[0].tagName) alert(test.children[1].tagName) children 代表对象的子节点数组--> document.all.tbl.child
Top