<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style type="text/css">
div{
border:2px solid #F00;
width:300px;
height:200px;
}
</style>
</head>
<body>
<div>
<p id="demo">123</p>
</div>
<p id="test">456</p>
<script>
var m=document.getElementById("demo");
var n=document.getElementById("test");
m.appendChild(n);
</script>
</body>
</html>
代码实现的是讲一个已经存在的p元素添加给div 元素,当实现添加后,原来p元素被删除,添加后的p元素被添加到div元素里面