【发布时间】:2021-10-24 09:32:44
【问题描述】:
这是我的代码,但只有一个字带下划线
$(document).ready(function() {
let firstword = 'web';
let secondword = 'js';
$(".field.ConditionsAccept>.caption:contains('" + secondword + "'):contains('" + firstword + "')").each(function() {
var regex = new RegExp("(" + secondword + ")", 'g');
var regex2 = new RegExp("(" + firstword + ")", 'g');
$(this).html($(this).text().replace(regex, '<span class="word" style="text-decoration: underline">$1</span>'));
$(this).html($(this).text().replace(regex2, '<span class="word2" style="text-decoration: underline">$1</span>'));
});
});
.ConditionsAccept { width: 500px; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table class="field ConditionsAccept">
<caption class="caption">Here is some web and js stuff</caption>
</table>
【问题讨论】:
-
请附上相关的html
-
欢迎来到 Stack Overflow!访问help center,使用tour 了解内容和How to Ask。如果您遇到困难,请发布您的尝试minimal reproducible example,并使用
[<>]sn-p 编辑器记录输入和预期输出。 -
我来这里是为了一些好的 C# 标签,而我所能看到的只是修饰过的 JavaScript。失望是轻描淡写。 专业提示:正确标记您的问题,否则您只会被否决
-
我为你修好了 sn-p。下次请自行提供minimal reproducible example
-
开心的时候请访问how to accept an answer
标签: javascript jquery css regex