文本的某些部分在锚标记内部html中重复。
<a href="" class="abc">There is some text some text some text some text </a>
但我希望输出删除重复文本。
必需的输出
<a href="" class="abc">There is some text</a>
如何删除锚标记内部html中的重复文本? “一些文字”这个词在几页中重复出现。我只需要摆脱多次出现的“一些文字”。我需要浏览页面中的所有锚标记,如果出现不止一次,请删除“some text”一词。
答案 0 :(得分:0)
脚本可以这样写:
var a = "There is some text some text some text some text";
var unique = [];
(a.split(' ')).forEach(function(text) {
if (unique.indexOf(text) < 0) {
unique.push(text);
}
});
document.write(unique.join(' '));
&#13;
您现在可以尝试将其放入<a>
标记