使用jQuery自动完成标签的utf-8问题 [英] utf-8 problem in using jquery autocomplete tags

查看:68
本文介绍了使用jQuery自动完成标签的utf-8问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙伴们.最近我使用了jQuery自动完成标记

http://devthought.com/projects/jquery/textboxlist/

一切正常,除了utf-8标签建议,仅建议英文标签

我猜脚本行出了点问题 它适用于英语标签,但不适用于波斯语等多字节语言

解决方案

很可能是TextboxList.Autocomplete.js中的第212行:

regexp = new RegExp('\\b' + escapeRegExp(search), insensitive ? 'i' : '');

这是在单词边界后寻找给定的字符.但是单词边界取决于单词字符的识别,JavaScript RegExp的单词字符列表只是ASCII字母数字加_.因为RegExp对Unicode一无所知,所以在单词以非ASCII字符开头的情况下将无法正常工作.

您可以尝试摆脱\\b的情况,在这种情况下,它会匹配任何建议,并在其中的任何位置都匹配给定的字符串,而不仅仅是在单词开头.

hey mates . recently i used jquery auto-complete tag

http://devthought.com/projects/jquery/textboxlist/

everything goes fine except utf-8 tag suggesting , only English tags are suggested

i guess something goes wrong with script lines it works fine with English tags but not with multi byte languages like Persian

解决方案

Probably line 212 in the TextboxList.Autocomplete.js is to blame:

regexp = new RegExp('\\b' + escapeRegExp(search), insensitive ? 'i' : '');

That's looking for the given character after a word boundary. But word boundaries are dependent on recognition of word characters, and JavaScript RegExp's list of word characters is just the ASCII alphanumerics plus _. Because RegExp knows nothing about Unicode this won't work where the word begins with a non-ASCII character.

You could try getting rid of the \\b in which case it would match any suggestion with the given string anywhere inside it, not just at the start of words.

这篇关于使用jQuery自动完成标签的utf-8问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆