我正在尝试遵循这个解决方案,但没有得到任何运气。 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);
没有错误,但它似乎没有正确绑定(bind)它...如果有人有任何想法,请发帖。谢谢。
最佳答案
尝试改变这一行:
$(input.id).autocomplete(autocomp_opt);
为此:
$('#' + input.id).autocomplete(autocomp_opt);
关于javascript - 动态输入文本框未绑定(bind)到自动完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7856129/