<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>创建删除节点</title>
</head>
<body>
<ul>
<li>li</li>
</ul>
<script>
const ul = document.querySelector('ul')
for (let index = 0; index < 3; index++) {
// 创建节点
const li = document.createElement('li')
// 添加子节点
li.innerText = 'li' + (index + 1)
ul.appendChild(li) // 向后面添加节点
}
ul.insertBefore(document.createElement('li'), ul.children[0]) // 向前面添加节点 insertBefore(添加的节点, 添加在谁的前面)
// 删除子节点
ul.removeChild(ul.children[3])
</script>
</body>
</html>