我想要遵循這個解決方案,但沒有得到任何運氣。 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