jQuery AutoComplete-结果显示编码的字符 [英] jQuery AutoComplete - Result shows encoded characters
问题描述
我正在使用以下代码使用自动完成插件在ajax文件中搜索查询:
I'm using the following code to search an ajax file for a query with the autocomplete plugin:
$("input.search_bar").autocomplete("/autocomplete/", {
scrollHeight: 300,
minChars: 3
});
搜索结果是HTML编码的名称,例如:
The search results are HTML encoded names like:
鲍勃的商店(确实是Bob%39s Store
)
比尔的商店(确实是Bill%39s Shop
)
等等...
Bob's Store (really Bob%39s Store
)
Bill's Shop (really Bill%39s Shop
)
etc...
自动完成"下拉列表显示正确的HTML,如下所示:
The autocomplete dropdown shows the correct HTML like so:
鲍勃的商店 比尔的商店
Bob's Store Bill's Shop
但是当我选择其中一个结果并将结果移入输入字段时,输入字段将显示转义的值,如下所示:
But when I select one of the results and the result moves into the input field, the input field displays the escaped value like so:
Bob%39s Store
如何使用jQuery的自动完成插件来格式化的结果,以显示转义值被选择的结果,当?
How do I use the jQuery Autocomplete plugin to format the result to show the unescaped value when a result is chosen?
我尝试了以下插件功能,但没有任何运气:
I've tried the following plugin function without any luck:
$("input.search_bar").autocomplete("/autocomplete/", {
scrollHeight: 300,
minChars: 3,
formatResult: function(row) {
return unescape(row);
}
});
推荐答案
尝试此代码,
$("input.search_bar").autocomplete("/autocomplete/", {
scrollHeight: 300,
minChars: 3,
formatResult: function(row) {
return $('<div/>').html(row).html();
}
});
这篇关于jQuery AutoComplete-结果显示编码的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!