You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 15:01:13