<!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]为什么不行呀,我希望每次点击都是在最前面插入?不是每次点击都创建一个li,然后在这个索引第0个前插入,应该是没问题的呀
添加回答
举报
0/150
提交
取消