Kir*_*lla 2 jquery jquery-ui autocomplete
可以在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
}
});
Run Code Online (Sandbox Code Playgroud)
骗过你
查看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'
});
});
Run Code Online (Sandbox Code Playgroud)
编辑2013年9月22日:源链接已修复,但不再维护.
| 归档时间: |
|
| 查看次数: |
3172 次 |
| 最近记录: |