动态输入文本框未绑定到自动完成
我正在尝试遵循这个解决方案,但没有得到任何运气。 动态创建输入的 jQuery 自动完成
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);
没有错误,但似乎没有正确绑定它...如果有人有任何想法,请发帖。谢谢。
I am trying to follow this solution, but not getting any luck.
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
};
And then when my input box gets generated, I tried...
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);
There was no errors, but it doesn't seem to bind it correctly...if anyone has any idea-please post. thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将此行:更改
为:
Try changing this line:
to this:
当我添加:
在这一行之后,
我想它只能在输入框附加到某些内容时才能注册。还值得注意的是,添加某种事件句柄 onfocus、onselect,即..,它也可以工作。尽管我怀疑,这是因为输入框此时已完全渲染/添加。
It works when I add:
after this line
I guess it can only registered when the input box is appended to something. It's also worth noting that adding some sort of event handle onfocus, onselect, ie.., it also works. Though I suspect, it's because the input box is fully rendered/added at this point.