查找操作并使用jquery突出显示该单词

时间:2016-09-15 09:15:03

标签: jquery

当我在上面的htmltext上执行查找操作""时,它应突出显示"""使用span标签的背景颜色的单词

<span class="highlight">the</span>

结果:

<p style="font-size:12pt; line-height:115%; margin:0pt"><span style="font-family:Calibri; font-size:12pt">[Pick <span class="highlight">the</span> date] a n d s height</span></p>

1 个答案:

答案 0 :(得分:0)

HTML

<p style="font-size:12pt; line-height:115%; margin:0pt">
<span style="font-family:Calibri; font-size:12pt" id="targetSpan">[Pick the date] a n d s height</span>
</p>

jquery的

var spanText = $('#targetSpan').html().replace("the","<span class='highlight'>the</span>");
$('#targetSpan').html(spanText);