在自动完成框中键入带重音的单词会显示其他字符
使用 ajax 自动建议脚本在我输入名称时查询 mysql 数据库。当我输入带有重音符号的姓名时,下拉列表显示的字符与我输入的字符不同。例如,当我输入姓氏 Hylén 时,Ajax 下拉列表显示 Hylén。如果该名称不在数据库中,则会发生这种情况。
$(document).ready(function(){
$("input[id^='last_']").autocomplete('suggest.php',{
matchCase:true,
formatItem: function(data, i, total)
{
var s=data[0].split(",")
return s.join(" ");
}
});
$("input[id^='last_']").result(function(event, data, formatted){
var ids=this.id.split('_')
var id=ids[1]; // from last_xx got xxx
var s=html_entity_decode(data[0]).split(","); // first,middle,last
$(this).next().focus();
$(this).next().select();
//have only last value -- TAB pressed
if(s.length==1)return;
$('#first_'+id).val(s[0]);
$('#middle_'+id).val(s[1]);
$('#last_'+id).val(s[2]);
});
});
我应该注意什么来解决这个问题?
Using an ajax autosuggest script that queries a mysql database as I enter names. As I type in a name with an accent, the dropdown shows different characters than the ones I've typed in. For example as I type in the last name Hylén, the Ajax dropdown shows Hylén. This occurs if the name is not in the database.
$(document).ready(function(){
$("input[id^='last_']").autocomplete('suggest.php',{
matchCase:true,
formatItem: function(data, i, total)
{
var s=data[0].split(",")
return s.join(" ");
}
});
$("input[id^='last_']").result(function(event, data, formatted){
var ids=this.id.split('_')
var id=ids[1]; // from last_xx got xxx
var s=html_entity_decode(data[0]).split(","); // first,middle,last
$(this).next().focus();
$(this).next().select();
//have only last value -- TAB pressed
if(s.length==1)return;
$('#first_'+id).val(s[0]);
$('#middle_'+id).val(s[1]);
$('#last_'+id).val(s[2]);
});
});
What should I be looking at to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你应该看看你的编码。看起来“é”是“é”的 2 个 Unicode 字节,打印为 ANSI 或其他。确保您在
希望有帮助!
I think you should look at your encoding. Looks like "é" is the 2 Unicode bytes of "é" printed as ANSI or whatever. Make sure that you use UTF8 (or UTF16 or whatever charset can handle all your characters) consistently in
Hope that helps!