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

移除含photos或prototypes文本的h4标签的HTML处理请求

移除特定文本内容的h4标签解决方案

这里有几种实用的方法帮你移除内容为photos或prototypes的<h4>标签,根据你的项目场景来选就好:

1. 原生JavaScript动态处理

如果需要在页面加载时自动处理,用原生JS就能实现,无需依赖第三方库:

// 选中所有带有h4类的h4元素
const targetH4s = document.querySelectorAll('h4.h4');

targetH4s.forEach(element => {
  // 去除文本前后空白,避免空格干扰判断
  const content = element.textContent.trim();
  // 匹配目标文本则移除元素
  if (content === 'photos' || content === 'prototypes') {
    element.remove();
  }
});

2. jQuery简化写法(如果项目已引入jQuery)

如果你项目里已经在用jQuery,可以用更简洁的代码实现:

$('h4.h4').filter(function() {
  const content = $(this).text().trim();
  return content === 'photos' || content === 'prototypes';
}).remove();

3. 静态HTML手动修改

如果你的HTML是静态文件,直接手动删除对应的标签最直接。把原始代码里的这两行删掉:

<h4 class='h4'>photos</h4>
<h4 class='h4'>prototypes</h4>

就能得到你想要的最终HTML结构:

<div class='wrap'> 
  <div class='col'> 
    <h4 class='h4'>videos</h4> 
    <h4 class='h4'>weight</h4> 
  </div> 
  <div class='col'> 
    <h4 class='h4'>color</h4> 
    <h4 class='h4'>selfie</h4> 
    <h4 class='h4'>front</h4> 
    <h4 class='h4'>back</h4> 
  </div> 
</div>

内容的提问来源于stack exchange,提问作者sourav kukreti

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.13 07:20:19