Highlight words with (and without) accented characters / diacritics in jQuery

匿名 (未验证) 提交于 2019-12-03 03:08:02

问题:

I'm using the jquery.highlight plugin: http://code.google.com/p/gce-empire/source/browse/trunk/jquery.highlight.js?r=2

I'm using it to highlight search results.

The problem is that if I search something like "café" it won't highlight any words.

And if I search "cafe", even though my results contains both "cafe" & "café", it will only highlight "cafe".

So, I would need to highlight all "versions" of the words, with or without diacritics.

Is that possible?

回答1:

http://jsfiddle.net/nHGU6/

Test HTML:

 <div id="wrapper-accent-sensitive">  <p>cafe</p>  <p>asdf</p>  <p>café</p> </div> <hr /> <div id="wrapper-not-accent-sensitive">>  <p>cafe</p>  <p>asdf</p>  <p>café</p> </div> 

Test CSS:

 .yellow {     background-color: #ffff00; } 

Replacement Javascript:

Test code:

$(document).ready(function() {     $("#wrapper-accent-sensitive").highlight("cafe", { className: 'yellow' });     $("#wrapper-not-accent-sensitive").highlight("cafe", { className: 'yellow', accentInsensitive: true }); }); 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!