运行 ❯
获取你
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>The Element Object</h1> <h2>The removeAttributeNode() Method</h2> <a id="myAnchor" href="https://w3schools.org.cn">A Link: Go to w3schools.com</a> <p id="demo">Click "Remove" to remove the href attribute node from the a element.</p> <button onclick="myFunction()">Remove</button> <script> function myFunction() { const element = document.getElementById("myAnchor"); const attr = element.getAttributeNode("href"); element.removeAttributeNode(attr); } </script> </body> </html>