javascript-动态输入文本框未绑定到自动完成
作者:互联网
我正在尝试遵循此解决方案,但没有任何运气.
jQuery autocomplete for dynamically created inputs
var autocomp_opt = {
source: function (request, response) {
$.ajax({
url: "ServiceProxy.asmx/ByKeyWord",
cache: false,
data: "{ 'term':'" + request.term + "'}",
dataType: "json",
type: "POST",
crossDomain: "true",
contentType: "application/json; charset=utf-8",
error: function (xhr, textStatus, errorThrown) {
alert('Error: ' + xhr.responseText);
},
success: function (data) {
response($.map(data, function (item) {
return item.split(",");
}));
},
error: function (a, b, c) {
}
});
},
minLength: 2
};
然后在生成输入框时,我尝试了…
input = document.createElement("input");
input.disabled = true;
input.className = this.FORM_INPUT_CLASS;
$(input.id).autocomplete(autocomp_opt);
table.rows[table.rows.length - 1].cells[1].appendChild(input);
没有错误,但是似乎没有正确绑定它……如果有人有任何想法请发表.谢谢.
解决方法:
尝试更改此行:
$(input.id).autocomplete(autocomp_opt);
对此:
$('#' + input.id).autocomplete(autocomp_opt);
标签:jquery-autocomplete,jquery-ui,autocomplete,javascript,jquery 来源: https://codeday.me/bug/20191202/2086568.html