【问题标题】:jQuery fuzzy search with bold带有粗体的 jQuery 模糊搜索
【发布时间】:2013-09-02 19:17:25
【问题描述】:
我正在寻找一些插件/脚本来搜索一些字符串和粗体匹配部分(模糊搜索)
在父级> key > 结果示例下。
"Hello world" => "hel" => Hello world
"Hello world" => "hewd" => Hello world
我找到了this - 它有模糊选项,但它不能加粗匹配部分或部分字符串。
你知道这样的插件吗?
【问题讨论】:
标签:
javascript
jquery
fuzzy-search
【解决方案1】:
一个简单的例子:
$('element').html(function() {
return $(this).text().replace(/[hewd]/gi, '<strong>$&</strong>');
});
然后您可以通过构建动态正则表达式来抽象它。以上将匹配任何h,e,w,d 字母,如果要匹配整个单词,可以使用单词边界\b:
/\bhello\b|[ewd]/ //=> Will match "hello" and all "e,w,d" letters
演示: http://jsbin.com/OKUjAtO/3/edit