x
 
<!DOCTYPE html>
<html>
<body>
<h1>Element 对象</h1>
<h2>replaceChild() 方法</h2>
<ul id="myList">
  <li>Coffee</li>
  <li>Tea</li>
  <li>Milk</li>
</ul>
<p>单击该按钮可替换列表中的第一项。</p>
<button onclick="myFunction()">试一试</button>
<script>
function myFunction() {
  const element = document.createElement("li");
  const textNode = document.createTextNode("Water");
  element.appendChild(textNode);
  const list = document.getElementById("myList");
  list.replaceChild(element, list.children[0]);
}
</script>
</body>
</html>