JavaScript 中是否有任何内置函数只获取元素节点,或者我是否必须添加另一个循环来计算这些节点的实际数量(如果我之前需要它),例如:
l = 0;
for(i = 0; i < x.childNodes.length; i++){
if(x.childNodes[i].nodeType = 1) l++;
}
for(i = 0; i < x.childNodes.length; i++){
if(x.childNodes[i].nodeType != 1) continue;
new Something(l);
}
最佳答案
Node.children is a read-only property that returns a live HTMLCollection of the child elements of Node.
语法
var elList = elementNodeReference.children;
elList is a HTMLCollection, which is an ordered collection of DOM elements that are children of elementNodeReference. If there are no element children, then elList contains no elements and has a length of 0.
关于javascript - JS获取指定类型的XML节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32415464/