<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>Document</title></head><body> <input id="wb" type="text" /> <input id="an" type="button" value="按鈕" /> <ul id="ul1"> </ul> <script> window.onload=function() { var oWb = document.getElementById("wb"); var btn = document.getElementById("an"); var oUl = document.getElementById("ul1"); btn.onclick=function() { var oLi = document.createElement("li"); oLi.innerHTML = oWb.value; oUl.insertBefore(oLi,oLi[0]); } } </script></body></html>最后這一句 oUl.insertBefore(oLi,oLi[0]); 選擇插入在oLi[0]為什么不行呀,我希望每次點(diǎn)擊都是在最前面插入?不是每次點(diǎn)擊都創(chuàng)建一個(gè)li,然后在這個(gè)索引第0個(gè)前插入,應(yīng)該是沒問(wèn)題的呀
為何CreateElement之后,在這標(biāo)簽前插入子節(jié)點(diǎn),沒用
慕工程0101907
2018-11-13 17:17:08