<!DOCTYPE html> <html> <body> <h1>Element 对象</h1> <h2>insertAdjacentText() 方法</h2> <button onclick="myFunction()">Insert</button> <p>单击“插入”可在标题中插入一些文本:</p> <h2 id="myH2">我的标题</h2> <script> function myFunction() { const h2 = document.getElementById("myH2"); let text = "我的插入文本"; h2.insertAdjacentText("afterbegin", text); } </script> </body> </html>