javascript如何获得子元素的个数 博客园备份

转载 https://zhidao.baidu.com/question/424734839.html

var childNum = document.getElementById('parent').children.length;
children属性能获得所有的子元素节点
var childNum = document.getElementById('parent').childNodes.length;
childNodes属性获得包含文本节点的子节点,但是firefox和ie不一样
firefox会获得空节点

posted @ 2018-12-27 11:33  select&action  阅读(456)  评论(0编辑  收藏  举报