您好,欢迎访问一九零五行业门户网

javascript如何删除meta标签

删除meta标签的方法:1、利用removechild()方法删除,语法“meta元素对象.parentnode.removechild(meta元素对象)”;2、利用remove()方法删除,语法“meta元素对象.remove()”。
本教程操作环境:windows7系统、javascript1.8.5版、dell g3电脑。
方法1、使用removechild()方法删除meta标签元素
<!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()">点击这里</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标签元素对象 function fun() { meta.parentnode.removechild(meta); down.innerhtml = "元素被删除!"; } </script> </body></html>
效果图:
方法2、使用remove()方法从文档中删除meta标签元素
<!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()">点击这里</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标签元素对象 function fun() { meta.remove(); down.innerhtml = "meta元素被删除!"; } </script> </body></html>
效果图:
【推荐学习:javascript高级教程】
以上就是javascript如何删除meta标签的详细内容。
其它类似信息

推荐信息