gpt4 book ai didi

jquery - 如何将自定义 HTML 添加到 jQuery 自动完成项?

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

是否可以向 jquery 自动完成 ui 项目添加一些 html?例如,我想添加 <strong></strong>自动完成结果项目的标签 label: item['name'] 。我尝试过 label: '<strong>'+item['name']+'</strong> ,但它作为文本应用,而不是 HTML。

$('input[name="customer"]').catcomplete({
delay: 0,
source: function(request, response) {
$.ajax({
url: 'index.php?route=sale/customer/autocompletefilter_name=' + encodeURIComponent(request.term),
dataType: 'json',
success: function(json) {
response($.map(json, function(item) {
return {
category: item['customer_group'],
label: item['name'],
customer : item['name'],
value: item['customer_id'],
customer_group_id: item['customer_group_id'],
firstname: item['firstname'],
lastname: item['lastname'],
email: item['email'],
telephone: item['telephone'],
fax: item['fax'],
address: item['address']
}
}));
}
});
},
select: function(event, ui) {
//some actions on select
}
});

谢谢你。

最佳答案

查看 Scott Gonzales 的自动完成 HTML 扩展 - https://github.com/scottgonzalez/jquery-ui-extensions/blob/master/src/autocomplete/jquery.ui.autocomplete.html.js 。它将允许您传入 HTML 作为标签选项。

示例 - http://jsfiddle.net/eay3d/1/

$(function() {
var availableTags = [
{ label: 'Apple1', value:'Apple1' },
{ label: '<strong>Apple2</strong>', value:'Apple2' },
{ label: 'Apple3', value:'Apple3' }
];
$( "#tags" ).autocomplete({
source: availableTags,
html: 'html'
});
});
<小时/>

编辑 09/22/2013:源链接已修复,但不再维护

关于jquery - 如何将自定义 HTML 添加到 jQuery 自动完成项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11382385/

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