如何用JavaScript替换<head>中被两个HTML注释包裹的所有标签
替换HTML head中指定注释包裹的内容
我需要修改HTML文档的<head>标签:删除由两个特定注释(通过注释文本内容识别)包裹的所有内容(包含这两个注释本身),并替换为新的内容块。
替换前示例
<head> <title>My Website</title> <meta property="test" content="some content" /> ... <!-- This is the first comment --> <meta property="hi" content="something" /> <link rel="canonical" href="http://website.com/test/"> <!-- This is the second comment --> ... <link rel="dns-prefetch" href="//use.typekit.net"> </head>
替换后示例
<head> <title>My Website</title> <meta property="test" content="some content" /> ... <!-- This is the first NEW comment --> <meta property="hi" content="something new" /> <link rel="canonical" href="http://website.com/hi-im-new/"> <meta property="hiagain" content="something completely new" /> <!-- This is the second NEW comment --> ... <link rel="dns-prefetch" href="//use.typekit.net"> </head>
内容的提问来源于stack exchange,提问作者user3371597
相关产品推荐
相关产品推荐

