jquery怎么实现搜索文本高亮

用户在页面上搜索某个关键字时,将关键词高亮显示;

高亮样式自己可以重新定义:

例如:span.highlight { color:red; font-weight:blod;}

使用高亮:

$(‘#fancy-text’).highLight();//清除高亮
$(‘#fancy-text’).highLight(“mode”);//显示高亮
就这么简单。我觉得jquery实现搜索文本高亮,比用正则替换方法要用些。

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>