刪除meta標(biāo)簽的方法:1、利用removeChild()方法刪除,語法“meta元素對象.parentNode.removeChild(meta元素對象)”;2、利用remove()方法刪除,語法“meta元素對象.remove()”。
本教程操作環(huán)境:windows7系統(tǒng)、javascript1.8.5版、Dell G3電腦。
方法1、使用removeChild()方法刪除meta標(biāo)簽元素
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" id="remove"> </head> <body style="text-align:center;"> <p style="font-size: 19px; font-weight: bold;">單擊按鈕刪除meta元素</p> <button onClick="Fun()">點(diǎn)擊這里</button> <p id="DOWN" style="color: green; font-size: 24px; font-weight: bold;"> </p> <!-- Script to remove HTML element --> <script> var down = document.getElementById('DOWN'); var meta = document.getElementById('remove'); //獲取meta標(biāo)簽元素對象 function Fun() { meta.parentNode.removeChild(meta); down.innerHTML = "元素被刪除!"; } </script> </body> </html>
效果圖:
方法2、使用remove()方法從文檔中刪除meta標(biāo)簽元素
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" id="remove"> </head> <body style="text-align:center;"> <p style="font-size: 19px; font-weight: bold;">單擊按鈕刪除meta元素</p> <button onClick="Fun()">點(diǎn)擊這里</button> <p id="DOWN" style="color: red; font-size: 24px; font-weight: bold;"> </p> <!-- Script to remove HTML element --> <script> var down = document.getElementById('DOWN'); var meta = document.getElementById('remove'); //獲取meta標(biāo)簽元素對象 function Fun() { meta.remove(); down.innerHTML = "meta元素被刪除!"; } </script> </body> </html>
效果圖:
【推薦學(xué)習(xí):javascript高級教程】