JS-节点遍历

        <script type="text/javascript">
           function makeList() {
               var div = document.getElementById("div1");
               var iterator = document.createNodeIterator(div, NodeFilter.SHOW_ELEMENT, null, false);
               var output = document.getElementById("text1");
               var node = iterator.nextNode();
               while (node !== null) {
                   output.value += node.tagName + "\n";
                   node = iterator.nextNode();
               }
           }
        </script>
        <script type="text/javascript">
           function makeList() {
                var div = document.getElementById("div1");
                var filter = function(node){
                    return (node.tagName.toLowerCase() == "li") ?
                        NodeFilter.FILTER_ACCEPT :
                        NodeFilter.FILTER_SKIP;
                };
                var iterator = document.createNodeIterator(div, NodeFilter.SHOW_ELEMENT, filter, false);
                //For Firefox: iterator = document.createTreeWalker(div, NodeFilter.SHOW_ELEMENT, filter, false);
                var output = document.getElementById("text1");
                var node = iterator.nextNode();
                while (node !== null) {
                    output.value += node.tagName + "\n";
                    node = iterator.nextNode();
                }
           }
        </script>