首页 > 代码库 > js创建子节点

js创建子节点

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>js创建子节点</title>
</head>
<body>

<ul id="test">
  <li>JavaScript</li>
  <li>HTML</li>
</ul>
 
<script type="text/javascript">

  var otest = document.getElementById("test");  
  var newnode=document.createElement("li");
  newnode.innerHTML="This is a new li";
  otest.appendChild(newnode);
</script>

</body>
</html>

js创建子节点