var otest = document.getElementById("test");
var x=otext.lastChild;
var newcode=document.createElement("li");
newcode.innerHTML="php";
otest.insertBefore(newcode,x);
var otest = document.getElementById("test"); var x = otest.lastChild; //你之前的是otext 变量名写错了 var newcode = document.createElement("li") newcode.innerHTML = "PHP"; otest.insertBefore(otest, x);
var x=otext.lastChild; 这里是otest.lastChild;