Javascript 如何在主体选择器中编写自动完成
我正在尝试编写以下脚本:-Javascript 如何在主体选择器中编写自动完成,javascript,jquery,autocomplete,Javascript,Jquery,Autocomplete,我正在尝试编写以下脚本:- $('body').on("autocomplete", "#ServerTag", autocomplete () { minLength: 1, delay: 1000, source: function (request, response) { $.ajax({ url: "@Url.Content("~/Server/AutoComplete")",
$('body').on("autocomplete", "#ServerTag", autocomplete () {
minLength: 1, delay: 1000,
source: function (request, response) {
$.ajax({
url: "@Url.Content("~/Server/AutoComplete")",
dataType: "json",
data: {
term: request.term,
},
success: function (data) {
response(data);
}
});
},
});
但似乎我写不出自动完成后的一个机构。对吗?我想以这种方式编写它,以允许在新内容上运行autocomplete。
有人可以提供建议吗?您可以尝试使用focus.autocomplete的live event 差不多
$("#ServerTag").live("focus.autocomplete", null, function () {});
而不是
$('body').on("autocomplete", "#ServerTag", autocomplete () {});
这可能会让你开始,所以你的意思是我需要使用“$”(“#ServerTag”).live(“focus.autocomplete”,null,function(){”而不是“$”('body”).on(“autocomplete”,“#ServerTag”,autocomplete(){”是的,你可以尝试使用liveyes它工作,谢谢!!,如果你觉得正确,请标记为答案,谢谢