最佳答案
在 JQuery 用户界面1.8.4之前,我可以在我构建的用于自动补全的 JSON 数组中使用 超文本标示语言。
我可以做一些像这样的事情:
$row_array['label'] = '<span style="color: red; font-family: courier;">User, Name</span>';
它将在下拉列表中显示为红色文本。
到1.8.4为止,这不起作用。我找到了 http://dev.jqueryui.com/ticket/5275,它告诉我使用自定义的 HTML 示例 给你,我没有运气。
我怎样才能让 HTML 显示在建议中呢?
我的 jQuery 是:
<script type="text/javascript">
$(function() {
$("#findUserIdDisplay").autocomplete({
source: "ui_autocomplete_users_withuname.php",
minLength: 2,
select: function(event, ui) {
$('#findUserId').val(ui.item.id);
}
});
});
</script>
我的 JSON 数组包含如下 HTML:
[{"label":"<span style="color: red";>User, Name</span>","value":"User, Name","id":"10"}]