我正在尝试使用 javascript 使用文本突出显示选项。我知道如何找到字符串的起始位置,但如何使它突出显示。我的代码看起来像
<div id="entity">health insurance</div>
<div id="article">This kind of insurance is meant to supplement health insurance for cancer-care costs. But generally you're better off putting your money toward comprehensive health policies. </div>
和我用过的javascript
$(document).ready(function()
{
var test=document.getElementById('article').innerHTML;
var variable=document.getElementById('entity').innerHTML;
alert(test.search(new RegExp(variable, "i")));
});
这将提醒字符串的起始位置。