我想要遵循这个解决方案,但没有得到任何运气。 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);
有没有错误,但它似乎没有,如果有人要正确绑定它...有任何想法 - 请发布。谢谢。
检查您的浏览器的JavaScript控制台。你最终会以'input.id'没有被定义,很可能。 – Bojangles
为什么不使用append和live jquey函数? – Mostafa
input.id在其他地方定义并确实显示正确。你能举一个这样的自动完成的例子。我看过的示例与鼠标点击有关。但是,这只是一个预定义的功能,所以我不确定。 jQuery的语法正在杀死我...... – wirble