var newnode = document.createElement("li");
newnode.innerHTML = "PHP";
otest.insertBefore(newnode.otest.childNodes[1]);
<script type="text/javascript">
var otest = document.getElementById("test");
var oli=document.createElement('li');
oli.innerHTML='php';
var olast=otest.lastChild;
otest.insertBefore(oli,olast);
</script>
查了几遍,没看出来,逗号 写成了句号.
otest.insertBefore(newnode,otest.childNodes[1]);
otest.insertBefore(newnode,otest.childNodes[1]);
<script type="text/javascript"> var otest = document.getElementById("test"); var newnode = document.createElement("li"); newnode.innerHTML = "PHP"; var ohtml = document.getElementsByTagName("li")[1]; otest.insertBefore(newnode,ohtml); </script>
<script type="text/javascript">
var otest = document.getElementById("test");
var node=document.createElement("li");
node.innerHTML="php";
otest.insertBefore(node,otest.childNodes[1]);
</script>
otest.insertBefore(newnode,otest.childNodes[1]);
如果你是复制的代码,恭喜你 请看第三行! 那个逗号哪去了??
最开始otest要获值吧,otest都没定义
加个 var otest=document.getElementById("你想输的id")