大家好,我在学习js的基础知识,在学习遍历文档节点时,有一段代码,为什么不能正常运行呢,代码如下
<html>
<head>
<script>
// This function is passed a DOM Node object and checks to see if that node
// represents an HTML tag-i.e., if the node is an Element object. It
// recursively calls itself on each of the children of the node, testing
// them in the sameway. It returns the total number of Element objects
// it encounters. If you invoke this function by passing it the 
// Document object, it traverses the entire DOM tree.
function countTags(n){
    var numtags = 0;
    if (n.nodeType == 1 /*Node.ELEMENT_NODE*/)
        numtags++;
    var children = n.childNodes;
    for(var i=0; i<children.length;i++){
        numtags+=countTags(childen[i]);
        }
    return numtags;
}
</script>
</head>
<!-- Here's an example of how the countTags() function might be used -->
<body onload="alert('This document has '+countTags(document)+'tags')">
This is a <i>sample</i> document.
</body> 
</html>