<html>
<body>
<h1>Document 对象</h1>
<h2>createDocumenFragment() 方法</h2>
<p>将数组项添加到空列表:</p>
<ul id="myList">
</ul>
<script>
const fruits = ["香蕉", "桔子", "芒果"];
// 创建文档片段:
const dFrag = document.createDocumentFragment();
for (let x in fruits) {
const li = document.createElement('li');
li.textContent = fruits[x];
dFrag.appendChild(li);
}
// 将片段添加到列表中:
document.getElementById('myList').appendChild(dFrag);
</script>
</body>
</html>