jquery - 使用 JQuery 删除重复的 div
问题描述
我有以下结构:
<div class="section-header Generator" style="display: table-row;">Generator</div>
<div class="section-header Generator" style="display: table-row;">Generator</div>
<div class="section-header Generator" style="display: table-row;">Generator</div>
<div class="section-header Engine" style="display: table-row;">Engine</div>
<div class="section-header Engine" style="display: table-row;">Engine</div>
<div class="section-header Battery" style="display: table-row;">Battery</div>
使用 JQuery,我想删除重复项 - 所以上面的列表将变为:
<div class="section-header Generator" style="display: table-row;">Generator</div>
<div class="section-header Engine" style="display: table-row;">Engine</div>
<div class="section-header Battery" style="display: table-row;">Battery</div>
任何想法我将如何实现?这里有一个旧答案,但似乎与我的问题无关
解决方案
解决方案在这里 - 我意识到我使用了错误的搜索词:
var seen = {};
$('.table-section-header').each(function() {
var txt = $(this).text();
if (seen[txt])
$(this).remove();
else
seen[txt] = true;
});
推荐阅读
- loopback - 环回 - 无法显示来自控制器的错误
- kotlin - 如果列表已经按其中两个字段排序,如何按三个字段对对象列表进行排序?
- excel - Excel - 使用嵌套的 IF COUNTIF 查找范围内的 3 个值的计数,以及它们是否小于或大于静态数字
- macos - LivenessProbe 失败,但端口转发正在同一端口上工作
- python - 可安装的 Python tar.gz 包取决于用于构建 tarball 的操作系统
- python - 如何使用 Python 查找数据集的时间间隔?
- python - 我无法在终端中使用 pip 命令安装 pygame
- jwt - 突然运行coral.cloudiot.core apperas时出错
- ios - 如何在 UIView 子类中通过 UIView 约束 UITableView 并在 UIViewController 中保留 dataSource 和委托方法?
- javascript - 将 JavaScript 数据发送到 Rails