【发布时间】:2012-06-14 00:10:26
【问题描述】:
我正在尝试使用 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")));
});
这将提醒字符串的起始位置。
【问题讨论】:
-
澄清你的问题。你想强调什么,是包含文本的div吗?
-
实体id里面的内容应该在文章id里面高亮..
标签: javascript jquery highlighting