gpt4 book ai didi

jquery - 使 jquery :Contains accent insensitive

转载 作者:行者123 更新时间:2023-12-01 00:18:55 25 4
gpt4 key购买 nike

我有这个不区分大小写的自定义选择器:

jQuery.expr[':'].Contains = function(a,i,m) {
var text = jQuery(a).text().toUpperCase();
var words = m[3].split(/\s+/);
for(var i = 0; i < words.length; i++) {
if (-1 == text.indexOf(words[i].toUpperCase())) {
return false;
}
}
return true;
};

它工作得很好,但它会因为重音而变得困惑。我的问题很简单,如何使这个选择器不区分大小写和重音

我正在考虑使用带有正则表达式的字符映射表,但我似乎无法使其正常运行。

感谢您的帮助。

最佳答案

我在 Github 上找到了这个,它对我来说非常有用: https://gist.github.com/oziks/3664787

jQuery.expr[':'].contains = function(a, i, m) {
var rExps=[
{re: /[\xC0-\xC6]/g, ch: "A"},
{re: /[\xE0-\xE6]/g, ch: "a"},
{re: /[\xC8-\xCB]/g, ch: "E"},
{re: /[\xE8-\xEB]/g, ch: "e"},
{re: /[\xCC-\xCF]/g, ch: "I"},
{re: /[\xEC-\xEF]/g, ch: "i"},
{re: /[\xD2-\xD6]/g, ch: "O"},
{re: /[\xF2-\xF6]/g, ch: "o"},
{re: /[\xD9-\xDC]/g, ch: "U"},
{re: /[\xF9-\xFC]/g, ch: "u"},
{re: /[\xC7-\xE7]/g, ch: "c"},
{re: /[\xD1]/g, ch: "N"},
{re: /[\xF1]/g, ch: "n"}
];

var element = $(a).text();
var search = m[3];

$.each(rExps, function() {
element = element.replace(this.re, this.ch);
search = search.replace(this.re, this.ch);
});

return element.toUpperCase()
.indexOf(search.toUpperCase()) >= 0;
};

关于jquery - 使 jquery :Contains accent insensitive,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14628989/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com