运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往空间
<!DOCTYPE html> <html> <body> <h1>The Element Object</h1> <h2>The insertBefore() Method</h2> <ul id="myList1"> <li>Coffee</li> <li>Tea</li> </ul> <ul id="myList2"> <li>Water</li> <li>Milk</li> <li>Juice</li> </ul> <p>Click the button to move items from one list to another:</p> <button onclick="myFunction()">Try it</button> <script> function myFunction() { const node = document.getElementById("myList2").lastElementChild; const list = document.getElementById("myList1"); list.insertBefore(node, list.children[0]); } </script> </body> </html>