<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
</head>
<body>
<ul id="test"><li>JavaScript</li><li>HTML</li></ul>
<script type="text/javascript">
var otest = document.getElementById("test");
var node=document.getElementsByTagName(li)[1];
var newnode=document.createElement("li");
top.innerHTML="php";
otest.insertBefore(newnode,node);
</script>
</body>
</html>
修改后:
var otest = document.getElementById("test");
var node=document.getElementsByTagName("li")[1];
var newnode=document.createElement("li");
newnode.innerHTML="php";
otest.insertBefore(newnode,node);
修改:
var node=document.getElementsByTagName(li)[1]; // li要加上""
top.innerHTML="php"; // top? 应该是newnode吧