DOM节点子集合-有什么区别? [英] DOM node child collections--what's the difference?

查看:65
本文介绍了DOM节点子集合-有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

节点的child和childNodes集合之间有什么区别?还有childElementCount和childNodes.length?

What's the difference between the children and childNodes collections of a node? And childElementCount and childNodes.length?

推荐答案

element.childNodes element.childNodes.length :包括子元素,文本节点(包括空格)元素之间的节点)和注释(可能还有CDATASections,ProcessingInstructions,DocumentTypes和EntityReferences,具体取决于文档和解析器).由 DOM 1级核心定义标准,并且已在每种浏览器上使用了很多年.

element.childNodes and element.childNodes.length: includes child elements, text nodes (including whitespace nodes between elements) and comments (plus potentially CDATASections, ProcessingInstructions, DocumentTypes and EntityReferences, depending on the document and parser). Defined by the DOM Level 1 Core standard and has been available on every browser for many years.

element.children element.childElementCount :仅包含 个元素节点,因此在某些情况下更易于处理. childElementCount 元素遍历API 标准定义并且在Mozilla,Opera和WebKit的最新版本中可用. children 没有任何标准定义,但是可以在IE和Mozilla,Opera,WebKit和IE的最新版本中使用.

element.children and element.childElementCount: includes only element nodes, so can be simpler to handle in some cases. childElementCount is defined by the Element Traversal API standard and is available in the latest versions of Mozilla, Opera and WebKit. children is not defined by any standard, but is available in IE and up-to-date versions of Mozilla, Opera, WebKit and IE.

这篇关于DOM节点子集合-有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆