<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <ul> <li>11</li> <li>22</li> <li>33</li> <li>44</li> <li>55</li> <li>66</li> </ul> <script> var oUl = document.getElementsByTagName("ul")[0]; var newNode = document.createElement("li"); var xxnode =document.getElementsByTagName("li"); newNode.innerHTML = "hello world!"; oUl.insertBefore(newNode,xxnode[0]); </script> </body> </html>
我想问的是,这个方法第二个参数索引的时候,不算空白节点么? 我发现直接按正常的0,1,2,3去取值就可以。这是为什么
zhangyudemuke
相关分类