场景

单击按钮将项目从一个列表移动到另一个列表中

提示:如果文档树中已经存在了 newchild,它将从文档树中删除,然后重新插入它的新位置。如果 newchild 是 DocumentFragment 节点,则不会直接插入它,而是把它的子节点按序插入当前节点的 childNodes[] 数组的末尾。

你可以使用 appendChild() 方法移除元素到另外一个元素。

实例

转移某个列表项到另外一个列表项:

var node=document.getElementById("myList2").lastChild;
document.getElementById("myList1").appendChild(node);

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
</head>
<body>

<ul id="myList1"><li>Coffee</li><li>Tea</li></ul>
<ul id="myList2"><li>Water</li><li>Milk</li></ul>
<p id="demo">单击按钮将项目从一个列表移动到另一个列表中</p>
<button onclick="myFunction()">点我</button>
<script>
function myFunction(){
	var node=document.getElementById("myList2").lastChild;
	document.getElementById("myList1").appendChild(node);
}
</script>

</body>
</html>