【发布时间】:2019-10-26 05:13:01
【问题描述】:
我有一个包含 v-html 结果的表格(因此表格内的文本在页面呈现之前不会存在)。我想比较两行,如果它们有重复的单词,那么它们应该被突出显示。
这是我想要的example project,但远远超出了我需要的范围。我的问题看起来最像this one in the stacks,但它需要定义这些词,我希望页面自己找到它们。
例如,这将是预期的输出:
<table>
<tr>
<td v-html="link.orderdesciption">
order:<br />
<mark> TV </mark><br /> <!--note that the contents of the td would not appear in markup due to being v-html-->
PS3 <br />
Laptop
</td>
<td>
qty:<br />
1<br />
2<br />
1<br />
</td>
</tr>
<tr>
<td>
----------------
</td>
<td>
----------------
</td>
</tr>
<tr>
<td v-html="link.orderrecieved">
recieved:<br /> <!--same note as above, v-html only shows-->
<mark> TV </mark><br />
Desktop<br />
</td>
</tr>
</table>
我一直在做这个,但我真的不知道从哪里开始:
var text = $('td').text(),
words = text.split(' '),
sortedWords = words.slice(0).sort(),
duplicateWords = [];
for (var i=0; i<sortedWords.length-1; i++) {
if (sortedWords[i+1] == sortedWords[i]) {
duplicateWords.push(sortedWords[i]);
}
}
duplicateWords = $.unique(duplicateWords);
感谢您的建议,
【问题讨论】:
标签: javascript jquery html css vue.js