本帖最后由 pyboy 于 2014-5-27 08:06 编辑
看毕老师视频,在做练习时,效果一直- <script type="text/javascript">
- var strNodes = "";
- function listNode(node,level)
- {
- printInfo(node,level);
- level++;
- var nodes = node.childNodes;
- for(var x = 0;x < nodes.length;x++)
- {
- if(nodes[x].hasChildNodes())
- listNode(nodes[x],level);
- else
- printInfo(node[x],level);
- }
- }
- function getSpace(level)
- {
- var s="";
- for(var x=0; x<level ;x++)
- s +="|----";
- return s;
- }
-
- function printInfo(node,level)
- {
- alert("2");
- //strNodes += getSpace(level)+"name:"+node.nodeName+"...type:"+node.nodeType+"...value:"+node.nodeValue+"<br/>";
- strNodes += getSpace(level)+"name:"+node.nodeName+"....type:"+"<br/>";
- }
-
- function getNode()
- {
- alert("1");
- listNode(document,0);
- document.write(strNodes);
- }
- </script>
- </head>
- <body>
- <input type="button" value="练习" onclick="getNode()" />
- <div id="divid">
- abcdefg higklmn opqrst uvwxyz
- </div>
- <table>
- <tr>
- <td>单元格一</td>
- <td>单元格二</td>
- </tr>
- <tr>
- <td>单元格三</td>
- <td>单元格四</td>
- </tr>
- </table>
- <span>我是span
- </span>
- <!--我是一个注释-->
- </body>
- </html>
复制代码 出不来, |